I am trying to manipulate a date with some simple Javascript. The code is as follows:
var newDate = new Date("2013-07-23" + " 12:00:00");
console.log(newDate.toString());
newDate = new Date(newDate.getTime() - (24 * 60 * 60 * 1000));
console.log(newDate.toString());
var date = newDate.getFullYear() + "-" + ("0" + (newDate.getMonth() + 1)).slice(-2) + "-" + ("0" + newDate.getDate()).slice(-2);
console.log(date);
Essentially, I am converting
2013-07-23 -> Jul 22 2013 12:00:00 GMT+1000 -> 2013-07-22
It works fine in Chrome, you can test the code via this Fiddle. It always returns
"Invalid Date"
"Invalid Date"
"NaN-aN-aN"
For the three console.logs
in Firefox, but:
Tue Jul 23 2013 12:00:00 GMT+1000 (E. Australia Standard Time)
Mon Jul 22 2013 12:00:00 GMT+1000 (E. Australia Standard Time)
2013-07-22
For Chrome.