How to get timestamp value in php which is similar to getTime() in javascript

一曲冷凌霜 提交于 2019-12-31 07:41:32

问题


Following javascript code gives me output like : 1314066350368

new Date().getTime();

I would like to generate similar timestamp in PHP in order to get server's timestamp. kindly suggest me how to do it in PHP so my PHP code will generate exactly similar timestamps.

P.S. I do know about time() and microtime() functions in PHP. But i am looking forward to get similar outputs as i have mentioned above.


回答1:


Try this:

<?php
echo microtime(true)*1000;
?>



回答2:


Did you try int time ( void ), Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).




回答3:


the following php results time stamp that is similar to javascript 'new Date().getTime()'

function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec) * 100;
}


来源:https://stackoverflow.com/questions/7155707/how-to-get-timestamp-value-in-php-which-is-similar-to-gettime-in-javascript

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