Skip to content

Instantly share code, notes, and snippets.

@zolitch
Last active December 16, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zolitch/5452274 to your computer and use it in GitHub Desktop.
Save zolitch/5452274 to your computer and use it in GitHub Desktop.
Date Formatter (javascript) using "/Date(1366743323000)/"
formatDate = function( timestamp ){
/*
Could be either date type : /Date(1397397600000)/
Or : 2014-03-18T20:45:00
*/
var newDate = timestamp.indexOf('T') > -1 ? timestamp : parseInt(timestamp.split('(')[1])
, d = new Date(newDate)
, time
, minutes = (d.getMinutes() === 0) ? '00' : d.getMinutes()
;
time = d.getHours() + ':' +
minutes + ' on ' +
['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'][d.getDay()] + ' ' +
d.getDate() + ' ' +
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()] + ' ' +
d.getFullYear();
return time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment