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!