时间戳转换成日期

 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));

猜你喜欢

转载自www.cnblogs.com/lprosper/p/9313510.html