Convert UNIX timestamp to milliseconds

谁说胖子不能爱 提交于 2019-12-07 16:02:15

问题


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

回答1:


UNIX timestamps are in seconds. Multiply by 1000.




回答2:


If you really need proper presentation -- use number_format().

$timestamp = 1305593400;
$ms = $timestamp * 1000;
echo number_format($ms, 0, '.', '');

Result: 1305593400000




回答3:


I use it

$unix_date = (time("Ymd", strtotime($r->date)) *1000);



来源:https://stackoverflow.com/questions/6430126/convert-unix-timestamp-to-milliseconds

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