时间格式化函数

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;

  

上一篇:023-PHP常用数组函数


下一篇:iview Weapp index索引器 cityjs 增加每个城市的code值