JS 封装时间戳转日期格式

 

直接上代码吧 

function formateTimeStamp(time) {
var date = new Date(time);
var year = date.getFullYear();
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
}
 
调用示例:
formateTimeStamp(parseInt(result[i].date))
 
返回示例:
2020-06-23 17:03:10
 
 
 
 
 
作者:微微一笑绝绝子
出处:https://www.cnblogs.com/wwyxjjz/p/15136748.html
本博客文章均为作者原创,转载请注明作者和原文链接。
 
 
 
 
 
 
posted @ 2021-08-13 11:58  微微一笑绝绝子  阅读(86)  评论(0编辑  收藏  举报