Last active
November 21, 2018 05:22
-
-
Save hjst/1326755 to your computer and use it in GitHub Desktop.
Format a javascript Date object as a 12h am/pm time string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function format_time(date_obj) { | |
// formats a javascript Date object into a 12h AM/PM time string | |
var hour = date_obj.getHours(); | |
var minute = date_obj.getMinutes(); | |
var amPM = (hour > 11) ? "pm" : "am"; | |
if(hour > 12) { | |
hour -= 12; | |
} else if(hour == 0) { | |
hour = "12"; | |
} | |
if(minute < 10) { | |
minute = "0" + minute; | |
} | |
return hour + ":" + minute + amPM; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No.
It is absolutely deprecate