时间转换为时间戳
let timestamp1 = (new Date()).valueOf();
结果:1588868988873,通过valueOf()函数返回指定对象的原始值获得准确的时间戳值;
var timestamp2 = new Date().getTime();
结果:1588868993361,通过原型方法直接获得当前时间的毫秒值,准确;
var timestamp3 = Number(new Date()) ;
结果:1588868997152,将时间转化为一个number类型的数值,即时间戳; ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200508003024851.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0thaVNhckg=,size_16,color_FFFFFF,t_70)
时间戳转换为时间
function TimestampToDate(Timestamp) {
let date1 = new Date(Timestamp);
return date1.toLocaleDateString().replace(/\//g, "-") + " " + date1.toTimeString().substr(0, 8);
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200508003528382.png)
function TimestampToDate2(Timestamp) {
let now = new Date(Timestamp),
y = now.getFullYear(),
m = now.getMonth() + 1,
d = now.getDate();
return y + "-" + (m |