shell
shell

Reputation: 1937

javascript date equality confusion

I have two dates who are equal when new Date is used but their getTime()'s are different.

Here are both dates:

1) Wed Nov 25 2015 08:00:00 GMT-0500 (EST) 
2) Wed Nov 25 2015 08:00:00 GMT-0500 (EST)

Their getTime()'s are:

1) 1448456400924 
2) 1448456400000

Off by a small amount, What is the cause of this? I've used both setSeconds(0) and setMinutes(0) on one date, the logs are what you see.

Upvotes: 3

Views: 75

Answers (1)

jaggedsoft
jaggedsoft

Reputation: 4038

Javascript Dates have millisecond precision: The getTime() method returns the number of milliseconds between midnight of January 1, 1970 and the specified date.

var date = new Date().setMilliseconds(0)

The last 3 digits are the issue, and the above code would correct 1448456400924 to 1448456400000 as an example.

Upvotes: 2

Related Questions