JavaScript获取yyyy/MM/dd HH:mm:ss格式时间字符串

in 备忘 with 1 comment
function getNowFormatDate () {
    var d = new Date()
    return this.formatTime(d)
}
function formatTime(date) {
    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, month, day].map(this.formatNumber).join('/') + ' ' + [hour, minute, second].map(this.formatNumber).join(':')
}
function formatNumber(n) {
    n = n.toString()
    return n[1] ? n : '0' + n
}
Comments are closed.