Date
Date 생성자 함수
new Date(밀리초)
//서버의 시간 기준이 UTC인지 KST에 따라 사용에 주의할 것
new Date(86400000);
new Date(24 * 60 * 60 * 1000); //시간, 분, 초, ms로 나눠서 기록
new Date(문자열)
new Date('2020/03/26/10:00:00'); //KST (node에서는 설정따라)
new Date(년월일…)
new Date(2020, 2, 26, 10, 00, 00, 0); //KST (node에서는 설정따라)
Date 메서드
Date.now
UTC 기준(1970년 1월 1일 00:00:00)부터 현재시간까지의 밀리초
Data.parse
UTC 기준(1970년 1월 1일 00:00:00)부터 전달된 지정시간(문자열)까지의 밀리초
Date.UTC
UTC 기준(1970년 1월 1일 00:00:00)부터 전달된 지정시간까지의 밀리초
Date.UTC(1970, 0, 2); // 86400000
Date.prototype.getFullYear 년도
Date.prototype.setFullYear 년도 설정
Date.prototype.getMonth 월
주의 : 0~11임
Date.prototype.setMonth 월 설정
Date.prototype.getDate 날짜
Date.prototype.setDate 날짜 설정
Date.prototype.getDay 요일
0~6 일욜부터 시작
Date.prototype.getHours 시간
0~23
Date.prototype.setHours 시간 설정
Date.prototype.getMinutes 분
0~59
Date.prototype.setMinutes 분 설정
Date.prototype.getSeconds 초
0~59
Date.prototype.setSeconds 초 설정
Date.prototype.getMilliseconds 밀리초
0~999
Date.prototype.setMilliseconds 밀리초 설정
Date.prototype.getTime UTC기준부터 객체시간까지 밀리초
Date.prototype.setTime UTC기준부터 객체시간까지 밀리초 설정
Date.prototype.getTimezoneOffset UTC와 객체시간차(분단위)
Date.prototype.toDateString 문자열로 날짜 반환
Date.prototype.toTimeString 문자열로 시간 반환
Date.prototype.toISOString ISO형식으로 문자열 반환
Date.prototype.toLocaleString 전달한 locale로 날짜와 시간을 표현한 문자열 반환
const today = new Date('2020/7/24/12:30');
today.toString(); // Fri Jul 24 2020 12:30:00 GMT+0900 (대한민국 표준시)
today.toLocaleString(); // 2020. 7. 24. 오후 12:30:00
today.toLocaleString('ko-KR'); // 2020. 7. 24. 오후 12:30:00
today.toLocaleString('en-US'); // 7/24/2020, 12:30:00 PM
today.toLocaleString('ja-JP'); // 2020/7/24 12:30:00
Date.prototype.toLocaleTimeString 전달한 locale로 시간을 표현한 문자열 반환
const today = new Date('2020/7/24/12:30');
today.toString(); // Fri Jul 24 2020 12:30:00 GMT+0900 (대한민국 표준시)
today.toLocaleTimeString(); // 오후 12:30:00
today.toLocaleTimeString('ko-KR'); // 오후 12:30:00
today.toLocaleTimeString('en-US'); // 12:30:00 PM
today.toLocaleTimeString('ja-JP'); // 12:30:00
Intl(참고)
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Intl
숫자와 날짜등 i18n에 맞춰서 출력해줄 수 있음
'공부공부 > JS 딥다이브' 카테고리의 다른 글
[js 딥다이브] 32장 String (0) | 2024.02.15 |
---|---|
[js 딥다이브] 31장 RegExp (0) | 2024.02.15 |
[js 딥다이브] 29장 Math (0) | 2024.02.15 |
[js 딥다이브] 27장 배열 (0) | 2024.02.15 |
[js 딥다이브] 28장 Number (0) | 2024.02.15 |