/**

 * 时间转换
 * @param date
 * @returns {string}
 */
    formatDateTime: function (date) {
        var date = new Date(date * 1000);      //时间戳为10位需*1000,时间戳为13位的话不需乘1000
        console.log(date)
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        minute = minute < 10 ? ('0' + minute) : minute;
        var second = date.getSeconds();
        second = second < 10 ? ('0' + second) : second;

        return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
    },
    
    formatDateTime(1403058804);
    console.log(formatDateTime(1403058804));   //2014-06-18 10:33:24

MRZYD
145 声望10 粉丝

一个初学的小菜鸟,望各位大佬多多指教