Skip to content

Instantly share code, notes, and snippets.

@josephmosby
Created April 28, 2015 15:14
Show Gist options
  • Save josephmosby/5173c4d0d0804375f290 to your computer and use it in GitHub Desktop.
Save josephmosby/5173c4d0d0804375f290 to your computer and use it in GitHub Desktop.
JS Format an ISO8601 date as Django date string representation
var format_date = function(date) {
var month_names = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
js_date = new Date(date);
formatted_date = month_names[js_date.getMonth()] + ' ' + js_date.getDate() + ', ' + js_date.getFullYear()
+ ', ' + js_date.getUTCHours() + ':' + js_date.getUTCMinutes();
if(js_date.getHours() < 12) {
formatted_date += " a.m.";
} else {
formatted_date += " p.m.";
}
return formatted_date;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment