Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript date equality confusion

Tags:

javascript

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.

like image 377
shell Avatar asked Nov 20 '25 00:11

shell


1 Answers

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.

like image 189
jaggedsoft Avatar answered Nov 21 '25 15:11

jaggedsoft



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!