Jon Cage
Jon Cage

Reputation: 37490

Why does a creating a new Date() object from an existing one in Javascript not preserve the milliseconds field?

Why does the following code result in minDate having zero milliseconds?

maxDate = new Date(2013,0,1,0,0,1,200);
minDate = new Date(maxDate.getTime());

I'm looking at this in Chrome if that makes a difference?

Upvotes: 0

Views: 670

Answers (1)

Guffa
Guffa

Reputation: 700382

The minDate doesn't have zero for milliseconds. The milliseconds are there in maxDate and gets into minDate:

maxDate = new Date(2013,0,1,0,0,1,200);
console.log(maxDate.getMilliseconds());
minDate = new Date(maxDate.getTime());
console.log(minDate.getMilliseconds());

Output:

200
200

Demo: http://jsfiddle.net/Guffa/2FCvz/

Upvotes: 3

Related Questions