其他分享
首页 > 其他分享> > 时间格式化函数

时间格式化函数

作者:互联网

function getNow() {
    var tempDate = new Date(Date.now());
    var year = tempDate.getFullYear();
    var month = tempDate.getMonth() + 1;
    if(month < 10){
        month = 0 + month.toString();
    }
    var day = tempDate.getDate();
    if(day < 10){
        day = 0 + day.toString();
    }
    var hour = tempDate.getHours();
    if(hour < 10){
        hour = 0 + hour.toString();
    }
    var minute = tempDate.getMinutes();
    if(minute < 10){
        minute = 0 + minute.toString();
    }
    var seconds = tempDate.getSeconds();
    if(seconds < 10){
        seconds = 0 + seconds.toString();
    }
    return `${year}-${month}-${day} ${hour}:${minute}:${seconds}`;
}

module.exports.getNow = getNow;

  

标签:格式化,函数,seconds,tempDate,month,时间,var,toString,day
来源: https://www.cnblogs.com/pittle-z/p/15954956.html