3

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.

shell
  • 1,867
  • 4
  • 23
  • 39

1 Answers1

2

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.

jaggedsoft
  • 3,858
  • 2
  • 33
  • 41