将时间戳转成yyyy-MM-dd HH:mm:ss的格式

5年以前  |  阅读数:486 次  |  编程语言:JavaScript 
/** 

 * timestamp:1469085472490 

 */   

var timestampToFormatDate = function(timestamp){     

     var date = new Date();  date.setTime(timestamp);   

     var year = date.getFullYear();   

    var month = date.getMonth() + 1; 

     var day = date.getDate(); 

     var hour = date.getHours(); 

     var minute = date.getMinutes();   

  var second = date.getSeconds();

     return year + '-' + supplementZero(month,2) + '-' + supplementZero(day,2) + ' ' +   

        supplementZero(hour,2) + ':' + supplementZero(minute,2) + ':' + supplementZero(second,2);  

}

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8