时间:2021-07-01 10:21:17 帮助过:29人阅读
1.将时间戳转换成时间
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.将一个时间戳减去当前时间戳来得到秒数
var dateDifference=function(expire_time){//返回秒数 var timestamp = Date.parse(new Date());//当前时间 timestamp=timestamp/1000; expire_time=parseInt(expire_time/1000);//过期时间 return expire_time-timestamp; }
以上就是js时间与时间戳之间的转换实例详解的详细内容,更多请关注Gxl网其它相关文章!