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

     1 <html>
     2 <head>
     3     <meta charset="UTF-8">
     4     <title>Document</title>
     5 </head>
     6 <body>
     7     <script type="text/javascript">
     8         //生成时间戳
     9         var timestamp1 = Date.parse(new Date());
    10         var timestamp2 = (new Date()).valueOf();
    11         var timestamp3 = new Date().getTime();
    12 
    13         //时间戳转换成时间格式
    14         function timetrans(date){
    15             var date = new Date(date);//如果date为13位不需要乘1000
    16             var Y = date.getFullYear() + '-';
    17             var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    18             var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
    19             var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    20             var m = (date.getMinutes() <10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    21             var s = (date.getSeconds() <10 ? '0' + date.getSeconds() : date.getSeconds());
    22             return Y+M+D+h+m+s;
    23         }
    24 
    25         alert(timestamp1);
    26         alert(timestamp2);
    27         alert(timestamp3);
    28         alert(timetrans(timestamp1));
    29         alert(timetrans(timestamp2));
    30         alert(timetrans(timestamp3));
    31     </script>
    32 </body>
    33 </html>
  • 相关阅读:
    数据表管理admin
    HDU 5057
    HDU 5056
    HDU 6035(树形dp)
    CodeForces 586D
    Codeforces 940D
    CodeForces 820C
    TOJ4114(活用树状数组)
    2017CCPC中南地区赛 H题(最长路)
    CodeForces 544C (Writing Code)(dp,完全背包)
  • 原文地址:https://www.cnblogs.com/zk-zhou/p/8556511.html
Copyright © 2011-2022 走看看