Skip to content

Instantly share code, notes, and snippets.

@tebriel
Created January 31, 2012 03:17
Show Gist options
  • Save tebriel/1708512 to your computer and use it in GitHub Desktop.
Save tebriel/1708512 to your computer and use it in GitHub Desktop.
format time
function formatTime(e)
{
var hour_value = e.getHours();
var minutes_value = '00';
minute_value = e.getMinutes();
if (minute_value == 0)
{
minute_value = '00';
}
else if (minute_value < 10)
{
minute_value = '0' + minute_value;
}
var AMorPM = "AM";
if (hour_value > 12)
{
hour_value -= 12;
AMorPM = "PM";
}
if (hour_value == 0)
{
hour_value = 12;
}
var formatedTime = hour_value + ":" + minute_value + " " + AMorPM;
return formatedTime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment