Unix Timestamp from Now outputs as 1970 [duplicate]

。_饼干妹妹 提交于 2019-12-12 02:52:45

问题


I'd Like to generate some unix Timestamp in the future. therefore i use a generator like unixtimestamp.com. But when i use the any generated timestamp for example in a console.log in chrome or firefox it produces not the timestamp from now but a timestamp from 1970.

Example: 1462277206 is the Unix Timestamp for Tue May 3 12:06:46 2016 GMT.

But in the console new Date(1462277206) returns Sat Jan 17 1970 23:11:17 GMT+0100 (CET).

What am i doing wrong?

Thanks for your help!

Muff


回答1:


JavaScript date/time numbers are milliseconds since The Epoch, not seconds since The Epoch like old-style Unix Epoch values. If you have a value in seconds, multiply by 1000:

new Date(1462277206 * 1000);


来源:https://stackoverflow.com/questions/37001797/unix-timestamp-from-now-outputs-as-1970

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!