• js timestamp与datetime之间的相互转换


    1.  datetime转换成timestamp

    strdate = "2015-08-09 08:01:36:789";
    var d = new Date(strdate);
    var timestamp=Math.round(d.getTime());
    document.write("timestamp: "+timestamp+"<br>");
    输出:
    timestamp: 1439078496789
    其它方法:
    var timestamp = Date.parse(strdate);
    或者
    var timestamp = d.valueOf();
    注意:
    strdate要加上毫秒,不然再转换成datetime会丢失毫秒

    2.  timestamp转换成datetime

    function timeStamp2String (time){
            var datetime = new Date();
             datetime.setTime(time);
             var year = datetime.getFullYear();
             var month = datetime.getMonth() + 1;
             var date = datetime.getDate();
             var hour = datetime.getHours();
             var minute = datetime.getMinutes();
             var second = datetime.getSeconds();
             var mseconds = datetime.getMilliseconds();
             return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second+"."+mseconds;
    };
    var time = "1439078496789"; //or time=1439018115000; 结果一样
    var strdate2 = timeStamp2String(time);
    document.write("date: "+strdate2+"<br>");
    输出:
    date: 2015-8-9 8:1:36.789
  • 相关阅读:
    Django之模板层
    Django之视图层
    Django路由系统
    Django request对象与ORM简介
    浏览器不能访问bing
    SQL问题:com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value
    IDEA用Maven创建SpringMVC项目和配置
    离线安装pyinstaller
    flink1.11-报错问题
    maven的pom文件报红
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7348709.html
Copyright © 2020-2023  润新知