While working with Javascript, I encountered a puzzling issue involving the Date
object.
date1 = new Date(1970, 1, 1);
date2 = new Date("1970-01-01T13:00:00.000Z");
console.log(date1.getYear()); //70
console.log(date1.getMonth()); //1
console.log(date1.getDay()); //0 expect 1
console.log(date2.getYear()); //70
console.log(date2.getMonth()); //0 expect 1
console.log(date2.getDay()); //4 expect 1
What could be causing this unexpected output? Am I missing something important about the Date
object?
FIDDLE
UPDATE:
console.log(date1);
This code produces the following result:
Date 1970-01-31T14:00:00.000Z