Javascript JS new Date() format in different browsers

So if you ever use the command “new Date();” this is what you will get from various browsers


Google Chrome:
Thu May 03 2012 12:40:00 GMT-0500 (Central Daylight Time)

Thu May 03 2012 12:40:00 GMT-0500 (Central Daylight Time)

Thu May 03 2012 12:40:00 GMT-0500 (Central Daylight Time)


Internet Explorer 9:
Thu May 3 12:40:00 CDT 2012


Go figure… Everyone but Microsoft uses the same date format. There format doesn’t even make sense, why is the year after the time?


A workaround for IE so all browsers will instead produce Microsoft SQL datetime format


var nowin = new Date();


function mssqlDateTime(now){
var monthlookup=[‘Jan’,’Feb’,’Mar’,’Apr’,’May’,’Jun’,’Jul’,’Aug’,’Sep’,’Oct’,’Nov’,’Dec’];
var hours=now.getHours();
var safedate = monthlookup[now.getMonth()] + ” ” + now.getDate() + ” ” + now.getFullYear() + ” ” + hours + “:” + String(“0” + now.getMinutes()).slice(-2) + ampm;
return safedate;


openanalytics 1206 views

I'm a 35 year old UIUC Computer Engineer building mobile apps, websites and hardware integrations with an interest in 3D printing, biotechnology and Arduinos.

View Comments
There are currently no comments.

This site uses Akismet to reduce spam. Learn how your comment data is processed.