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

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title></title>
     6     </head>
     7     <body>
     8     </body>
     9     <script>
    10         //时间戳转换成日期,日期转换成时间戳
    11         var d = new Date(1293072805);
    12         console.log(d.getFullYear());//1970
    13         console.log(d.getMonth() + 1);//1        
    14         console.log(d.getDate());//15
    15 
    16         d.getTime();//日期转换成时间戳
    17         Date.parse();//日期转换成时间戳
    18         
    19         
    20         //时间戳转换成日期
    21         
    22         //方法1
    23         function getLocalTime(nS) {     
    24             return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:d{1,2}$/,' ');     
    25         }     
    26         console.log(getLocalTime(1293072805)); 
    27         
    28         //方法2
    29         function getLocalTime(nS) {     
    30             return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17)
    31         }
    32         console.log(getLocalTime(1293072805));  
    33 
    34         //方法3
    35         function formatDate(now) { 
    36             var year=now.getFullYear(); 
    37             var month=now.getMonth()+138             var odate=now.getDate(); 
    39             var hour=now.getHours(); 
    40             var minute=now.getMinutes(); 
    41             var second=now.getSeconds(); 
    42             return year+"-"+month+"-"+odate+" "+hour+":"+minute+":"+second; 
    43 44             
    45         var d=new Date(1230999938); 
    46         console.log(formatDate(d));
    47         
    48         
    49         
    50     </script>
    51 </html>
  • 相关阅读:
    pptpvpn链接问题
    nginx网站架构优化思路(原)
    KEEPALIVED 检测RS原理
    linux 做gw(nat)详细配置
    pptpvpn 连接后 无法上外网
    网站最常见的错误
    Python服务器开发 -- 网络基础
    python高性能编程方法一
    一步步来用C语言来写python扩展
    http响应Last-Modified和ETag
  • 原文地址:https://www.cnblogs.com/1032473245jing/p/7472174.html
Copyright © 2011-2022 走看看