바우보리

javascript 일자 함수 모음.

개발하면서 스크립트 함수 모았던것 입니다.

 

참조해서 사용하세요~

 

//현재일자
function getToday(seperate) {

    if(seperate == null || seperate == undefined) {
        seperate = ".";
    }

    // 오늘 날짜
    var nowDate = new Date();
    var nowYear = nowDate.getFullYear();
    var nowMonth = nowDate.getMonth() + 1;
    var nowDay = nowDate.getDate();

    if(nowMonth < 10){ nowMonth = "0" + nowMonth; }
    if(nowDay < 10) { nowDay = "0" + nowDay; }

    var todayDate = nowYear + seperate + nowMonth + seperate + nowDay;
    return todayDate;
}


//어제일자
function getYesterday(seperate, sDate) {
    if(seperate == null || seperate == undefined) {
        seperate = ".";
    }
    var nowDate = (sDate == null || sDate == undefined) ? new Date() : fnGetDate(sDate);

    // 어제 날짜
    var yesterDate = nowDate.getTime() - (1 * 24 * 60 * 60 * 1000);
    nowDate.setTime(yesterDate);

    var yesterYear = nowDate.getFullYear();
    var yesterMonth = nowDate.getMonth() + 1;
    var yesterDay = nowDate.getDate();

    if(yesterMonth < 10){ yesterMonth = "0" + yesterMonth; }
    if(yesterDay < 10) { yesterDay = "0" + yesterDay; }

    var resultDate = yesterYear + seperate + yesterMonth + seperate + yesterDay;
    return resultDate;
}

//1주전일자
function getBeforeOneWeekDay(seperate, sDate) {
    if(seperate == null || seperate == undefined) {
        seperate = ".";
    }
    var nowDate = (sDate == null || sDate == undefined) ? new Date() : fnGetDate(sDate);

    // 지난 1주
    var weekDate = nowDate.getTime() - (7 * 24 * 60 * 60 * 1000);
    nowDate.setTime(weekDate);

    var weekYear = nowDate.getFullYear();
    var weekMonth = nowDate.getMonth() + 1;
    var weekDay = nowDate.getDate();

    if(weekMonth < 10){ weekMonth = "0" + weekMonth; }
    if(weekDay < 10) { weekDay = "0" + weekDay; }

    var resultDate = weekYear + seperate + weekMonth + seperate + weekDay;

    return resultDate;
}


//2주전일자
function getBeforeTwoWeekDay(seperate, sDate) {
    if(seperate == null || seperate == undefined) {
        seperate = ".";
    }
    var nowDate = (sDate == null || sDate == undefined) ? new Date() : fnGetDate(sDate);

    // 지난 1주
    var weekDate = nowDate.getTime() - (14 * 24 * 60 * 60 * 1000);
    nowDate.setTime(weekDate);

    var weekYear = nowDate.getFullYear();
    var weekMonth = nowDate.getMonth() + 1;
    var weekDay = nowDate.getDate();

    if(weekMonth < 10){ weekMonth = "0" + weekMonth; }
    if(weekDay < 10) { weekDay = "0" + weekDay; }

    var resultDate = weekYear + seperate + weekMonth + seperate + weekDay;

    return resultDate;
}

// 당월의 1일
function getFirstDayOfMonth(seperate, sDate) {
    if(seperate == null || seperate == undefined) {
        seperate = ".";
    }

    // 오늘 날짜
    var nowDate = new Date();
    var nowYear = nowDate.getFullYear();
    var nowMonth = nowDate.getMonth() + 1;

    if(nowMonth < 10){ nowMonth = "0" + nowMonth; }

    var resultDate = nowYear + seperate + nowMonth + seperate + "0" + 1;
    return resultDate;
}

// 당월의 9일
function getNineOfMonth(seperate, sDate) {
    if(seperate == null || seperate == undefined) {
        seperate = ".";
    }

    // 오늘 날짜
    var nowDate = new Date();
    var nowYear = nowDate.getFullYear();
    var nowMonth = nowDate.getMonth() + 1;

    if(nowMonth < 10){ nowMonth = "0" + nowMonth; }

    var resultDate = nowYear + seperate + nowMonth + seperate + "0" + 9;
    return resultDate;
}

//1개월전일자
function getBeforeOneMonthDay(seperate, sDate) {
    if(seperate == null || seperate == undefined) {
        seperate = ".";
    }
    var nowDate = (sDate == null || sDate == undefined) ? new Date() : fnGetDate(sDate);

    // 지난 1달
    var addMonthDate = addMonth(nowDate, -1);

    var monthYear = addMonthDate.getFullYear();
    var monthMonth = addMonthDate.getMonth() + 1;
    var monthDay = addMonthDate.getDate();

    if(monthMonth < 10){ monthMonth = "0" + monthMonth; }
    if(monthDay < 10) { monthDay = "0" + monthDay; }

    var resultDate = monthYear + seperate + monthMonth + seperate + monthDay;

    return resultDate;
}

// 1개월 전의 1일
function getFirstDayOfBeforeMonth(seperate, sDate) {
    if(seperate == null || seperate == undefined) {
        seperate = ".";
    }
    var nowDate = (sDate == null || sDate == undefined) ? new Date() : fnGetDate(sDate);

    // 지난 1달
    var addMonthDate = addMonth(nowDate, -1);

    var monthYear = addMonthDate.getFullYear();
    var monthMonth = addMonthDate.getMonth() + 1;

    if(monthMonth < 10){ monthMonth = "0" + monthMonth; }

    var resultDate = monthYear + seperate + monthMonth + seperate + "0" + 1;

    return resultDate;
}

|

댓글 6개

한눈에 보기 쉽게 정리해 주셔서 감사합니다.
소중한글 감사합니다
공유 감사합니다~!
댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
21-07-25 조회 1만
21-07-24 조회 8,329
21-07-23 조회 8,627
21-07-23 조회 6,978
21-07-16 조회 8,594
21-07-14 조회 7,275
21-07-14 조회 5,901
21-07-12 조회 6,536
21-07-12 조회 6,346
21-07-09 조회 7,003
21-07-07 조회 6,341
21-07-06 조회 6,820
21-07-05 조회 7,686
21-07-05 조회 7,431
21-07-01 조회 7,361
21-06-30 조회 6,572
21-06-29 조회 9,666
21-06-29 조회 8,209
21-06-29 조회 9,108
21-06-29 조회 7,992
21-06-27 조회 8,179
21-06-24 조회 9,318
21-06-24 조회 8,267
21-06-24 조회 6,981
21-06-23 조회 1.1만
21-06-22 조회 8,798
21-06-22 조회 5,968
21-06-20 조회 8,306
21-06-20 조회 6,215
21-06-19 조회 7,300