Skip to content

Instantly share code, notes, and snippets.

@chrismendis
Created December 1, 2010 21:22
Show Gist options
  • Save chrismendis/724251 to your computer and use it in GitHub Desktop.
Save chrismendis/724251 to your computer and use it in GitHub Desktop.
Change the dates returned by Tumblr's tweet.js callback to something like 12:00 PM Oct. 27th
var prettyTweetDate = function (tweetDateFromJSON) {
var createDate = Date.parse(tweetDateFromJSON),
tweetDate = new Date(createDate),
tweetDateNum = tweetDate.getDate(),
tweetHours = tweetDate.getHours(),
tweetAMPM = (tweetHours < 12) ? "AM" : "PM",
tweetDateSuffix = "",
prettyTweetDateString = "",
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
tweetHours = (tweetHours < 13) ? tweetHours : tweetHours - 12;
if (tweetDateNum === 1 || tweetDateNum === 21 || tweetDateNum === 31) {
tweetDateSuffix = "st";
} else if (tweetDateNum === 2 || tweetDateNum === 22) {
tweetDateSuffix = "nd";
} else if (tweetDateNum === 3 || tweetDateNum === 23) {
tweetDateSuffix = "rd";
} else {
tweetDateSuffix = "th";
}
prettyTweetDateString += tweetHours + ":" + tweetDate.getMinutes() + " " + tweetAMPM + " " + months[tweetDate.getMonth()] + " " + tweetDateNum + tweetDateSuffix;
return prettyTweetDateString;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment