Igor Simic
7 years ago

Javascript new Date not working on IE and Safari



IE and Safari are little bit picky when it comes to passing and calculating dates using new Date, so for example this will not work on IE or Safari:

var date = new Date("2011-02-07");
because IE and Safari do not support this type of date format YYYY-MM-DD, to make it right here are the valid date formats that you can use:

var date = new Date(2011, 01, 07); // yyyy, mm-1, dd  
var date = new Date(2011, 01, 07, 11, 05, 00); // yyyy, mm-1, dd, hh, mm, ss  
var date = new Date("02/07/2011"); // "mm/dd/yyyy"  
var date = new Date("02/07/2011 11:05:00"); // "mm/dd/yyyy hh:mm:ss"  
var date = new Date(1297076700000); // milliseconds  
var date = new Date("Mon Feb 07 2011 11:05:00 GMT"); // ""Day Mon dd yyyy hh:mm:ss GMT/UTC