本文主要是介绍js时间戳和普通时间相互转换,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
var timestamp1 = Date.parse(new Date());
console.log(timestamp1); //输出当前时间的时间戳var date = new Date(1520324618000);
console.log(date);
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();
console.log(Y+M+D+h+m+s);
这篇关于js时间戳和普通时间相互转换的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!