将 UNIX 时间戳转换为毫秒
如何使用 PHP 获取 UNIX 时间戳,就像从 JS 方法 .getTime()
获取的那样?我似乎遇到了麻烦,因为 .getTime()
返回毫秒。我知道我必须先转换时间戳以便 JS 读取它,但是我该怎么做呢?
编辑:
同意乘以 1000,但为什么我会得到这个?:
timestamp: 1305593400
timestamp * 1000: 1.3055934E+12
timestamp: 1305612420
timestamp * 1000: 1.30561242E+12
timestamp: 1305635400
timestamp * 1000: 1.3056354E+12
timestamp: 1304901960
timestamp * 1000: 1.30490196E+12
timestamp: 1304944620
timestamp * 1000: 1.30494462E+12
How can I use PHP to get a UNIX timestamp like what I get from the JS method .getTime()
? I seem to be having trouble since .getTime()
returns milliseconds. I know I have to convert the timestamps first for JS to read it, but how can I do this?
Edit:
Agreed with the multiply by 1000, but why do I get this?:
timestamp: 1305593400
timestamp * 1000: 1.3055934E+12
timestamp: 1305612420
timestamp * 1000: 1.30561242E+12
timestamp: 1305635400
timestamp * 1000: 1.3056354E+12
timestamp: 1304901960
timestamp * 1000: 1.30490196E+12
timestamp: 1304944620
timestamp * 1000: 1.30494462E+12
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UNIX 时间戳以秒为单位。乘以 1000。
UNIX timestamps are in seconds. Multiply by 1000.
如果您确实需要正确的演示 - 使用number_format()。
结果: 1305593400000
If you really need proper presentation -- use number_format().
Result: 1305593400000
我用它
$unix_date = (time("Ymd", strtotime($r->date)) *1000);
I use it
$unix_date = (time("Ymd", strtotime($r->date)) *1000);