JS格式化时间函数,复制即用

JS格式化时间函数,复制即用

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(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(num){
    num = num.toString()
    return num[1] ? num : '0' + num
}


formatTime(1596663521410)


最后编辑于:2020/01/04作者: 牛逼PHP

发表评论