获取毫秒级时间戳

2021-06-24  本文已影响0人  _浅墨_
  /** 获取当前时间戳 */
    getNow() {
        debugger
        const today = new Date();
        var nowArr = [];
        const year = today.getFullYear();
        // 保留 0,比如6月显示为06月
        const month = (today.getMonth()+1<10?'0':'') + (today.getMonth()+1);
        const date = (today.getDate()<10?'0':'') + today.getDate();
        const hours = (today.getHours()<10?'0':'') + today.getHours();
        const minutes = (today.getMinutes()<10?'0':'') + today.getMinutes();
        // 精确到毫秒
        const seconds = (today.getMilliseconds()<10?'0':'') + today.getMilliseconds();
        nowArr.push(year);
        nowArr.push(month);
        nowArr.push(date);
        nowArr.push(hours);
        nowArr.push(minutes);
        nowArr.push(seconds);
        var dateTime = nowArr.join("");
        this.timestamp = dateTime;
    }
上一篇 下一篇

猜你喜欢

热点阅读