zoukankan      html  css  js  c++  java
  • JS 时间字符串与时间戳之间的转换

    1、当前时间换时间戳

    var timestamp = parseInt(new Date().getTime()/1000);    // 当前时间戳
    document.write(timestamp);

    2、当前时间换日期字符串

    var now = new Date();
    var yy = now.getFullYear();      //
    var mm = now.getMonth() + 1;     //
    var dd = now.getDate();          //
    var hh = now.getHours();         //
    var ii = now.getMinutes();       //
    var ss = now.getSeconds();       //
    var clock = yy + "-";
    if(mm < 10) clock += "0";
    clock += mm + "-";
    if(dd < 10) clock += "0";
    clock += dd + " ";
    if(hh < 10) clock += "0";
    clock += hh + ":";
    if (ii < 10) clock += '0'; 
    clock += ii + ":";
    if (ss < 10) clock += '0'; 
    clock += ss;
    document.write(clock);     //获取当前日期

    3、日期字符串转时间戳

    var date = '2015-03-05 17:59:00.0';
    date = date.substring(0,19);    
    date = date.replace(/-/g,'/'); //必须把日期'-'转为'/'
    var timestamp = new Date(date).getTime();
    document.write(timestamp);

    4、时间戳转日期字符串

    var timestamp = '1425553097';
    var d = new Date(timestamp * 1000);    //根据时间戳生成的时间对象
    var date = (d.getFullYear()) + "-" + 
               (d.getMonth() + 1) + "-" +
               (d.getDate()) + " " + 
               (d.getHours()) + ":" + 
               (d.getMinutes()) + ":" + 
               (d.getSeconds());
    document.write(date);

    转: https://www.cnblogs.com/cxf1992/p/10723694.html

  • 相关阅读:
    Python 面向对象(初级篇)
    python中的运算符
    初识Python
    浅谈计算机
    Zeppelin interperter 模式设置总结图解2
    maven 使用错误
    TensorFlow anaconda命令备忘
    zeppelin ERROR总结
    YARN 命令总结
    Zeppelin interperter 模式设置总结图解1
  • 原文地址:https://www.cnblogs.com/fps2tao/p/13167550.html
Copyright © 2011-2022 走看看