JS 현재 날짜 "yyy - MM - dd HH: mm: SS" 가 져 오기

1215 단어 JS
참고:https://www.cnblogs.com/hanwenhua/articles/3853352.html
function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        var strHour=date.getHours();
        var strMinu=date.getMinutes();
        var strSecond=date.getSeconds();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        if (strHour >= 0 && strHour <= 9) {
            strHour = "0" + strHour;
        }
        if (strMinu >= 0 && strMinu <= 9) {
            strMinu = "0" + strMinu;
        }
        if (strSecond >= 0 && strSecond <= 9) {
            strSecond = "0" + strSecond;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                + " " + strHour + seperator2 + strMinu
                + seperator2 + strSecond;
        return currentdate;
    }

좋은 웹페이지 즐겨찾기