javasript毫秒转换为成时间(年月日时分秒)

2025年03月05日 建站教程

日期格式方法

function dateFormat(str){
    var oDate = new Date(str),
    oYear = oDate.getFullYear(),
    oMonth = oDate.getMonth()+1,
    oDay = oDate.getDate(),
    oHour = oDate.getHours(),
    oMin = oDate.getMinutes(),
    oSen = oDate.getSeconds()
    return oYear+ "-" + zero(oMonth, 2) + "-" + zero(oDay, 2)+" "+zero(oHour, 2)+":"+zero(oMin, 2)+ ":"+ zero(oSen, 2);
};

补0操作1

function zero(num){
    if(parseInt(num) < 10){
        num = '0'+num;
    }
    return num;
}

输出结果:

console.log(dateFormat(1666678311838))
//2022-10-25 14:11:51

本文链接:http://so.lmcjl.com/news/24315/

展开阅读全文
相关内容