Home >Web Front-end >JS Tutorial >Detailed explanation of conversion examples between js time and timestamp

Detailed explanation of conversion examples between js time and timestamp

零下一度
零下一度Original
2017-07-19 17:46:521624browse

This article brings you detailed examples of conversion between js time and timestamp, as follows

1. Convert timestamp to time

var formatDate = function(d) { 
var now = new Date(d);
var year = now.getFullYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
return year + "-" + month + "-" + date + "   " + hour + ":" + minute + ":" + second;
}

2. Subtract a timestamp Go to the current timestamp to get the seconds

var dateDifference=function(expire_time){//返回秒数
var timestamp = Date.parse(new Date());//当前时间
timestamp=timestamp/1000;
expire_time=parseInt(expire_time/1000);//过期时间
return expire_time-timestamp;
}


The above is the detailed content of Detailed explanation of conversion examples between js time and timestamp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn