zoukankan      html  css  js  c++  java
  • 时间戳转换

    时间戳:分为两种:
       10位 单位秒
       13位 单位毫秒

    时间戳转换成2017/06/14 11:15

    currentTime(1500002100000);
    function currentTime(timestamp){
    timestamp = new Date(timestamp);
    var year = timestamp.getFullYear();
    var month = timestamp.getMonth() + 1;
    var date = timestamp.getDate();
    var hour = timestamp.getHours();
    var minute = timestamp.getMinutes();
    if(month < 10) {
    month = '0' + month;
    }
    if(date < 10) {
    date = '0' + date;
    }
    if(hour < 10) {
    hour = '0' + hour;
    }
    if(minute < 10) {
    minute = '0' + minute;
    }
    var currentdate = year +"/"+  month +"/"+ date + " "+hour +":"+ minute;
    alert(currentdate) ;
    }

     将时间转换成时间戳

    var timer = "2017/06/14 11:15"
    var date = new Date(timer);
    console.log(date.getTime());

    注意:

    // 1498665600000 var endTime = '2017/06/29'; 正确写法
    // 1498694400000 var endTime = '2017-06-29'; 错误写法

    补充:获得当前时间戳!!!

    Date.now()方法

    可以通过Date.now()方法获取当前的时间戳(13位)

    Date.now()
    1513665344622

    +new Date()方法 == Date.now()

    +new Date()
    1513665622909

    new Date().getTime()

    new Date().valueOf()

     时间转时间戳

    new Date('2017-12-20 13:50:44').getTime()
  • 相关阅读:
    tuple元组
    list列表
    OS模块
    time模块/datetime模块/calendar模块
    Codeforces Round #196 (Div. 2)
    【HDU 2853】 KM算法
    【HDU1914 The Stable Marriage Problem】稳定婚姻问题
    【HDU4585 Shaolin】map的经典运用
    【HDU4578 Transformation】线段树
    【HDU4632 Palindrome subsequence】区间dp
  • 原文地址:https://www.cnblogs.com/RAINHAN/p/7010766.html
Copyright © 2011-2022 走看看