首页 > 其他 > 详细

unix 时间戳转化为 日期格式

时间:2018-07-06 01:10:42      阅读:263      评论:0      收藏:0      [点我收藏+]
 1 function getMyTime(str,format) {
 2     var oDate = new Date(str*1000),  // 这个看后端给你的时间戳单位是秒,还是毫秒;如果是秒,需要乘以1000
 3         oYear = oDate.getFullYear(),
 4         oMonth = oDate.getMonth() + 1,
 5         oDay =  oDate.getDate(),
 6         oHour = oDate.getHours(),
 7         oMin = oDate.getMinutes(),
 8         oSen = oDate.getSeconds();
 9 
10     oTime = oYear + ‘-‘ + getzf(oMonth) + ‘-‘ + getzf(oDay)+ ‘ ‘ + getzf(oHour)+ ‘:‘ + getzf(oMin)+ ‘:‘ + getzf(oSen); //最后拼接时间
11 
12     if(format==="Y-m-d"){
13         dataTime= oTime.substr(0,10);
14     }else if(format==="Y-m-d-h-i"){
15         dataTime= oTime.substr(0,21);
16     }else if(format==="Y-m-d-h-i-s"){
17         dataTime= oTime;
18     }
19     return dataTime;
20 }
21 function getzf(num) {
22     if(parseInt(num) < 10) {
23         num = ‘0‘ + num;
24     }
25     return num;
26 }

 

unix 时间戳转化为 日期格式

原文:https://www.cnblogs.com/ycyweb/p/9270832.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!