このPHPコードに相当するJavascriptはありますか?
function secondsAgo($unixtime){
return time() - $unixtime;
}
使用例:
echo secondsAgo(time()-10); // 10
Javascriptにunixtimestampがあり、今日からそのタイムスタンプまでに何秒経過したかを調べる必要があります。
このPHPコードに相当するJavascriptはありますか?
function secondsAgo($unixtime){
return time() - $unixtime;
}
使用例:
echo secondsAgo(time()-10); // 10
Javascriptにunixtimestampがあり、今日からそのタイムスタンプまでに何秒経過したかを調べる必要があります。
JS相当:
function secondsAgo(unixTime) {
return Math.round((new Date().getTime() / 1000)) - unixTime;
}
JSタイムスタンプはUnix/PHPタイムスタンプと同じですが、JSが代わりにミリ秒を使用することを除いて、1970年1月からの時間です。
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.