获取格式化时间

// 获取当前时间
var getTime = function getTime(){
    var date = new Date();
    var year = date.getFullYear();
    if(year< 10){
        year = '0' + date.getFullYear();
    }
    var month = (date.getMonth()+1);
    if(month < 10){
        month = '0' + (date.getMonth()+1);
    }
    var day = date.getDate();
    if(day < 10){
        day = '0' + date.getDate();
    }
    var hour = date.getHours();
    if(hour < 10){
        hour = '0' + date.getHours();
    }
    var minutes = date.getMinutes();
    if(minutes < 10){
        minutes = '0' + date.getMinutes();
    }
    var second = date.getSeconds();
    if(second < 10){
        second = '0' + date.getSeconds();
    }
    var all_date = year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + second;
    return all_date
}

你可能感兴趣的:(获取格式化时间)