时间戳格式转化

时间:2021-11-06 02:37:45

1.格式化成 YY-MM-DD  HH:MM:SS

 1         formDate:function(time){
 2             var newDate = "";
 3             if(time !==""){
 4                 var d = new Date(time*1000),
 5                     y = d.getFullYear(),
 6                     m = d.getMonth() + 1,
 7                     dd = d.getDate(),
 8                     h = d.getHours(),
 9                     min = d.getMinutes(),
10                     s = d.getSeconds();
11                 newDate = y+"-"+m+"-"+dd+"  "+h+":"+min+":"+s;
12             }
13             return newDate;
14         }
formDate(1504662989) // "2017-9-6  9:56:29"