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

零下一度
Release: 2017-07-19 17:46:52
Original
1622 people have browsed it

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;
}
Copy after login

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;
}
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template