The integer value is in milliseconds, try adding 86400000
.
Javascript timestamp adding 24hrs
-
06-07-2023 - |
题
Using the javascript error console in chrome:
new Date()
Sat Apr 19 2014 21:31:35 GMT+0200 (W. Europe Summer Time)
new Date().getTime()
1397935905577
gives me a time stamp of now
it is a little hard to show you because time keeps moving (someone stop it for a sec please)
new Date(1397935465774);//a current time
Sat Apr 19 2014 21:24:25 GMT+0200 (W. Europe Summer Time)
new Date(1397935471308)//a current time plus 86400
Sat Apr 19 2014 21:24:31 GMT+0200 (W. Europe Summer Time)
because 24hrs is made of 86400 seconds, like this:
(new Date().getTime())+86400
1397936020170
but there is only like ten minutes (ish I can't tell time very well) difference
new Date(new Date().getTime())
Sat Apr 19 2014 21:33:40 GMT+0200 (W. Europe Summer Time)
new Date((new Date().getTime())+86400)
Sat Apr 19 2014 21:31:45 GMT+0200 (W. Europe Summer Time)
Why?
解决方案
其他提示
new Date().getTime()
gives you time in milliseconds, not seconds!
不隶属于 StackOverflow