달력

5

« 2025/5 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
2024. 5. 14. 10:56

javascript 함수정리 카테고리 없음2024. 5. 14. 10:56


    /* 현재일자 반환 YYYY-MM-DD */
    function getToday() {
        var date = new Date();
        return date.getFullYear() + "-" + ("0"+(date.getMonth()+1)).slice(-2) + "-" + ("0"+date.getDate()).slice(-2);
    }
   
    //당일  yyyymmdd
    function getTodayYMD( yyyy,mm,dd) {
        var now = new Date(yyyy,(mm-1),dd);
        if( empty(yyyy) || empty(mm) || empty(dd) ){
            now = new Date();
        }
        var year = now.getFullYear();
        var month = ("0" + (1 + now.getMonth())).slice(-2);
        var day = ("0" + now.getDate()).slice(-2);

        return year + month + day;
    }
    /*특정 날짜 시간형태값 구하기*/
    function getTimeInMillis(yyyy,mm,dd)
    {
        var toDay = new Date(yyyy,mm,dd);
        return toDay.getTime();
    }

    /*특정 날짜 요일 구하기*/
    function getTodayLabel(yyyy,mm,dd) {
        var week = new Array('일', '월', '화', '수', '목', '금', '토');
        var today = new Date(yyyy,(mm-1),dd);
        var todayLabel = week[today.getDay()];
        return todayLabel;
    }

    /*한달전 날짜 구하기*/
    function getPreMonth(yyyy,mm,dd) {
        var now = new Date(yyyy,(mm-1),dd);
        var preDay = new Date( now.setMonth( now.getMonth() -1 ) );
        return getTodayYMD(preDay.getFullYear(),preDay.getMonth()+1,'01');
    }

    /*한달후 날짜 구하기*/
    function getPostMonth(yyyy,mm,dd) {
        var now = new Date(yyyy,(mm-1),dd);
        var postDay = new Date( now.setMonth( now.getMonth() +1 ) );
        return getTodayYMD(postDay.getFullYear(),postDay.getMonth()+1,'01');
    }

    function getTodayD(yyyy,mm,dd) {
        var today = new Date(yyyy,(mm-1),dd);
        return today.getDay()+1; //java에서 일요일1 (javascript는 일요일0)
    }
   
    /* 해당달의 마지막 날짜 구하기 */
    function getlastDay(source) {
        source = source.replace(/\D/ig, "");
        if (isNaN(source) || source.length < 6) {
            return "";
        }
        var year  = source.substring(0, 4);
        var month = source.substring(4, 6);
        var newDate  = new Date(year, month, 0);

        var newYear  = newDate.getFullYear();
        var newMonth = newDate.getMonth()+1;
        var newDay   = newDate.getDate();
        console.log(newMonth);

        if (newMonth.toString().length < 2) newMonth = "0" + newMonth;
        if (newDay.toString().length < 2) newDay = "0" + newDay;

        return newYear.toString() + newMonth.toString() + newDay.toString();
       
    }
 

월의 마지막일반환

[JS] JavaScript 현재 날짜(시간) 및 월의 마지막 날짜(말일) 구하기 (tistory.com)

 

[JS] JavaScript 현재 날짜(시간) 및 월의 마지막 날짜(말일) 구하기

현재 날짜(시간) 가져오기 var now = new Date(); 현재시간 now.getYear(); 년 now.getMonth()+1; 월 월은 0부터 시작 0 = 1월, 1 = 2월 ... now.getDate(); 일 1 ~ 31 반환 now.getDay(); 요일 0 ~ 6 반환 / 월요일 ~ 일요일 now.getHo

joonpyo-hong.tistory.com

 

 

요일반환

출처 : Dev Life in IT :: [ 자바 코딩 ] 오늘 날짜, 요일, 시간 구하기 (Calendar 클래스) (tistory.com)

 

[ 자바 코딩 ] 오늘 날짜, 요일, 시간 구하기 (Calendar 클래스)

안녕하세요. 제임스 입니다. 이번에는 자바 Calendar 클래스를 이용하여 오늘 날짜, 요일 및 시간을 구하는 방법에 대해 알아 보겠습니다. import java.util.Calendar;Calendar cal = Calendar.getInstance(); System.out.

jamesdreaming.tistory.com

 

출처 : Date.prototype.getDay() - JavaScript | MDN (mozilla.org)

 

Date.prototype.getDay() - JavaScript | MDN

getDay() 메서드는 주어진 날짜의 현지 시간 기준 요일을 반환합니다. 0은 일요일을 나타냅니다. 현재의 일을 반환하려면 Date.prototype.getDate()를 사용하세요.

developer.mozilla.org

 

 

출처 : JavaScript / 함수 / parseFloat(), parseInt() – 문자열을 수로 바꾸는 함수 – CODING FACTORY

 

JavaScript / 함수 / parseFloat(), parseInt() - 문자열을 수로 바꾸는 함수

목차1 parseFloat()1.1 문법1.2 예제2 parseInt()2.1 문법2.2 예제 parseFloat() parseFloat()는 문자열을 실수로 바꾸는 함수입니다. 문법 parseFloat( string ) 수로 시작할 때 그 수를 실수로 바꿉니다. 띄어 쓰기로 여

www.codingfactory.net

 

 

출처 : [JavaScript] Math 함수 정리 (tistory.com)

 

[JavaScript] Math 함수 정리

[JavaScript] Math 함수 정리 Math is a built-in object that has properties and methods for mathematical constants and functions. It’s not a function object. -> Math 객체는 수학에서 자주 사용하는 상수와 함수들을 미리 구현해 놓

developing-stock-child.tistory.com

 

:
Posted by 상문이