Created
October 20, 2010 00:31
-
-
Save braden/635515 to your computer and use it in GitHub Desktop.
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
formatDateTime: function(dateTime) { | |
var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
var hour = dateTime.getHours(); | |
var postfix; | |
if (hour < 12) { | |
postfix = "AM"; | |
} else { | |
postfix = "PM"; | |
} | |
if (hour == 0) { | |
hour = 12; | |
} | |
if (hour > 12) { | |
hour = hour - 12; | |
} | |
var min = dateTime.getMinutes(); | |
min = min + ""; | |
if (min.length == 1) { | |
min = "0" + min; | |
} | |
var date = dateTime.getDate(); | |
var sup = ""; | |
if (date == 1 || date == 21 || date == 31) { | |
sup = "st"; | |
} | |
else if (date == 2 || date == 22) { | |
sup = "nd"; | |
} else if (date == 3 || date == 23) { | |
sup = "rd"; | |
} else { | |
sup = "th"; | |
} | |
return hour + ":" + min + " " + postfix + " " + ((new Date()).getDate() == dateTime.getDate() ? "" : months[dateTime.getMonth()] + " " + date + "<sup>" + sup + "</sup>"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment