• 0
  • 0

JS取十位时间戳

2019-10-23 26 0 admin 所属分类:Javascript

第一种

// type为true只获取时间戳10位 否则把连带毫秒数都拿出来
timestamp(type) {
    var timestamp = Date.parse(new Date());
    if (type != undefined) {
        var temp = timestamp.toString();
        timestamp = temp.substr(0, 10);
        timestamp = parseInt(timestamp);
    }
    return timestamp;
}
console.log(timestamp(true));

第二种

var TIMESTAMP = parseInt(new Date().getTime() / 1000);


返回顶部