序列化日期(yyyy-MM-dd hh:mm:ss)

var getDateFormat = function() {
    var _date = new Date(); //实例化一个Date对象
    var _complete = function(value) { //补全数值
        return(value > 9) ? value : '0' + value;
    };
    var year, month, day, hour, minute, second;
    year = _date.getFullYear();
    month = _complete(_date.getMonth() + 1); //month的取值范围(0-11)
    day = _complete(_date.getDate());
    hour = _complete(_date.getHours());
    minute = _complete(_date.getMinutes());
    second = _complete(_date.getSeconds());
    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
};

 

posted @ 2017-02-15 14:19  月半流云  阅读(264)  评论(0编辑  收藏  举报