使用js将Unix时间戳转换为普通时间

 

1 
var unixtime=1358932051;
formatTime (time) { 2 let unixtime = time 3 let unixTimestamp = new Date(unixtime * 1000) 4 let Y = unixTimestamp.getFullYear() 5 let M = ((unixTimestamp.getMonth() + 1) > 10 ? (unixTimestamp.getMonth() + 1) : '0' + (unixTimestamp.getMonth() + 1)) 6 let D = (unixTimestamp.getDate() > 10 ? unixTimestamp.getDate() : '0' + unixTimestamp.getDate()) 7 let toDay = Y + '-' + M + '-' + D 8 return toDay 9 }

 

posted @ 2017-07-11 16:10  豆浆油条123  阅读(8889)  评论(0编辑  收藏  举报