zoukankan      html  css  js  c++  java
  • 获取和解析时间戳

    js获取当前时间戳的三个方法

    let time1 = Date.parse(new Date())
    let time2 = new Date().valueOf()
    let time3 = new Date().getTime()
    第一种方法: Date.parse(new Date()) 获取的时间戳是把毫秒改成000显示
    第一种方法和第三种方法: Date.parse(new Date()) 获取的时间戳是把毫秒改成000显示

    js解析时间戳

    function timetrans(date) {
    var date = new Date(date);//如果date为13位不需要乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    console.log(M)
    var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return Y + M + D + h + m + s;
    }
    let time2 = new Date().valueOf()
    console.log(time2)
    timetrans(time2)
    console.log(timetrans(time2))
    console.log('0' + 3)












































































































  • 相关阅读:
    数据库设计范式
    SQL 触发器
    SQL查询上月和本月两个月的语句
    angularjs学习总结 详细教程
    指令
    重复 HTML 元素
    AngularJS 数据绑定
    AngularJS 指令.
    AngularJS 数组
    AngularJS 对象
  • 原文地址:https://www.cnblogs.com/zhouyideboke/p/9849487.html
Copyright © 2011-2022 走看看