Js 시간 전환 의 몇 가지 상황

2760 단어
JS 시간 전환 의 몇 가지 상황 
Case1: year+ month+date+hour+minut+second
        var datetime = new Date(time);
        //datetime.setTime(time);
        var year = datetime.getFullYear();
        var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
        var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
        var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
        var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
        var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
        return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;

 
Case2: /Date(1589699516247)/
function formater(val):{        
if
(val != null) { var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10)); // 0-11, +1, 10 0 var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); return date.getFullYear() + "-" + month + "-" + currentDate; } return "";
}

좋은 웹페이지 즐겨찾기