美文网首页
时间戳转换

时间戳转换

作者: lovelydong | 来源:发表于2018-03-07 19:17 被阅读0次

function timestampToTime(timestamp) {
var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
Y = date.getFullYear() + '-';
M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
D = date.getDate() + ' ';
h = date.getHours() + ':';
m = date.getMinutes() + ':';
s = date.getSeconds();
return Y+M+D+h+m+s;
}
timestampToTime(1403058804);
console.log(timestampToTime(1403058804));//2014-06-18 10:33:24

相关文章

网友评论

      本文标题:时间戳转换

      本文链接:https://www.haomeiwen.com/subject/badsfftx.html