有没有与此PHP代码等效的Javascript?
function secondsAgo($unixtime){
return time() - $unixtime;
}示例用法:
echo secondsAgo(time()-10); // 10我在Javascript中有一个unixtimestamp,需要找出从今天到这个时间戳已经过去了多少秒。
发布于 2013-02-05 06:08:41
JS等价物:
function secondsAgo(unixTime) {
return Math.round((new Date().getTime() / 1000)) - unixTime;
}发布于 2013-02-05 06:09:31
JS时间戳与Unix/PHP时间戳相同,均为1970年1月1日以来的时间,除了JS使用毫秒。
var msts = new Date().getTime(); // timestamps in millisecs;
var ts = msts / 1000; // now directly compariable to PHP timestamp.
var phpts = <?php echo json_encode(time()); ?>;
var diff = phpts - ts; // difference in seconds.https://stackoverflow.com/questions/14696538
复制相似问题