本文介绍了Unix 时间戳从现在输出为 1970的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在未来生成一些 unix Timestamp.因此我使用像 unixtimestamp.com 这样的生成器.但是,当我在 chrome 或 firefox 的 console.log 中使用任何生成的时间戳时,它生成的不是现在的时间戳,而是 1970 年的时间戳.

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.

示例:1462277206 是 2016 年 5 月 3 日星期二 12:06:46 GMT 的 Unix 时间戳.

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

但在控制台 new Date(1462277206) 返回1970 年 1 月 17 日星期六 23:11:17 GMT+0100(欧洲中部时间).

我做错了什么?

感谢您的帮助!

莫夫

推荐答案

JavaScript 日期/时间数字是自 The Epoch 以来的 毫秒,而不是自 The Epoch 以来的 像旧的一样-风格 Unix Epoch 值.如果您有一个以秒为单位的值,请乘以 1000:

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);

这篇关于Unix 时间戳从现在输出为 1970的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:43