码迷,mamicode.com
首页 > 其他好文 > 详细

时间戳转换成日期

时间:2018-07-15 16:14:56      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:页面   时间戳   timestamp   ret   nbsp   日期   function   mon   span   

 1     // 时间戳转换成日期
 2     function timestampToTime(timestamp) {
 3         var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
 4         Y = date.getFullYear() + ‘-‘;
 5         M = (date.getMonth() + 1 < 10 ? ‘0‘ + (date.getMonth() + 1) : date.getMonth() + 1) + ‘-‘;
 6         D = date.getDate() + ‘ ‘;
 7         h = date.getHours() + ‘:‘;
 8         m = date.getMinutes() + ‘:‘;
 9         s = date.getSeconds();
10         return Y + M + D + h + m + s;
11     }
12 
13 
14     // 页面输出时间
15     document.write(timestampToTime(1234567980123));

 

时间戳转换成日期

标签:页面   时间戳   timestamp   ret   nbsp   日期   function   mon   span   

原文地址:https://www.cnblogs.com/lprosper/p/9313510.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!