美文网首页
获取时间戳

获取时间戳

作者: 余霜序 | 来源:发表于2019-08-13 21:15 被阅读0次

获取时间戳

// 时间戳:1970年1月1日 8点距离现在的毫秒数

// 获取时间戳
//方法1:  通过getTime()
var now = new Date();
var time = now.getTime();
console.log(time);

// 方法二 将时间对象转换成数字   Number  一元运算
var now = new Date();
var time = Number(now);
console.log(time);

var time = + now;
console.log(time);

var time = parseInt(now);//parseInt不能转
console.log(time);

//方法三  valueOf 返回当前对象的最原始的值
var time = now.valueOf();
console.log(time);

//方法四 Date对象 不用实例化  直接拥有一个now方法  返回当前的毫秒数
var time = Date.now();
console.log(time);

相关文章

网友评论

      本文标题:获取时间戳

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