美文网首页
获取毫秒级时间戳

获取毫秒级时间戳

作者: _浅墨_ | 来源:发表于2021-06-24 18:32 被阅读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;
    }

相关文章

网友评论

      本文标题:获取毫秒级时间戳

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