Skip to content

Instantly share code, notes, and snippets.

@yoko
Created March 26, 2010 17:36
Show Gist options
  • Save yoko/345155 to your computer and use it in GitHub Desktop.
Save yoko/345155 to your computer and use it in GitHub Desktop.
function formatTumblrDate(date) {
var y = date.getFullYear();
var m = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][date.getMonth()];
var d = date.getDate();
d = d+(['st', 'nd', 'rd', 'th'][(/(1?\d)$/.exec(d))[1] - 1] || 'th');
var h = date.getHours();
var ampm = ['am', 'pm'][Number(h >= 12)];
h = h % 12;
var min = date.getMinutes();
if (min < 10) min = '0'+min;
return m+' '+d+', '+y+' '+h+':'+min+ampm;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment