
date.toLocaleString() 함수를 사용하여 날짜를 로컬 형식으로 문자열로 변환하는 방법은 다음과 같습니다.
- 첫 번째 방법:
#hostingforum.kr
javascript
const date = new Date();
const localeString = date.toLocaleString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit' });
console.log(localeString);
이 코드는 현재 날짜를 한국어로 '년-월-일' 형식으로 변환합니다.
- 두 번째 방법:
#hostingforum.kr
javascript
const date = new Date();
const localeString = date.toLocaleString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'Asia/Seoul' });
console.log(localeString);
이 코드는 현재 날짜를 한국 시간대에 맞게 '년-월-일' 형식으로 변환합니다.
- 세 번째 방법:
#hostingforum.kr
javascript
const date = new Date();
const localeString = date.toLocaleString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'Asia/Seoul', hour: '2-digit', minute: '2-digit', second: '2-digit' });
console.log(localeString);
이 코드는 현재 날짜와 시간을 한국 시간대에 맞게 '년-월-일 시간:분:초' 형식으로 변환합니다.
- 네 번째 방법:
#hostingforum.kr
javascript
const date = new Date();
const localeString = date.toLocaleString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'Asia/Seoul', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
console.log(localeString);
이 코드는 현재 날짜와 시간을 한국 시간대에 맞게 '년-월-일 시간:분:초' 형식으로 변환합니다.
- 다섯 번째 방법:
#hostingforum.kr
javascript
const date = new Date();
const localeString = date.toLocaleString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'Asia/Seoul', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
console.log(localeString.replace(' ', ''));
이 코드는 현재 날짜와 시간을 한국 시간대에 맞게 '년월일시간분초' 형식으로 변환합니다.
- 여섯 번째 방법:
#hostingforum.kr
javascript
const date = new Date();
const localeString = date.toLocaleString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'Asia/Seoul', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
console.log(localeString.replace(' ', '').replace('-', ''));
이 코드는 현재 날짜와 시간을 한국 시간대에 맞게 '년월일시간분초' 형식으로 변환합니다.
- 일곱 번째 방법:
#hostingforum.kr
javascript
const date = new Date();
const localeString = date.toLocaleString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'Asia/Seoul', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
console.log(localeString.replace(' ', '').replace('-', '').replace(':', ''));
이 코드는 현재 날짜와 시간을 한국 시간대에 맞게 '년월일시간분초' 형식으로 변환합니다.
- 여덟 번째 방법:
#hostingforum.kr
javascript
const date = new Date();
const localeString = date.toLocaleString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'Asia/Seoul', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
console.log(localeString.replace(' ', '').replace('-', '').replace(':', '').replace('.', ''));
이 코드는 현재 날짜와 시간을 한국 시간대에 맞게 '년월일시간분초' 형식으로 변환합니다.
- 아홉 번째 방법:
#hostingforum.kr
javascript
const date = new Date();
const localeString = date.toLocaleString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'Asia/Seoul', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
console.log(localeString.replace(' ', '').replace('-', '').replace(':', '').replace('.', '').replace('/', ''));
이 코드는 현재 날짜와 시간을 한국 시간대에 맞게 '년월일시간분초' 형식으로 변환합니다.
- 열 번째 방법:
#hostingforum.kr
javascript
const date = new Date();
const localeString = date.toLocaleString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'Asia/Seoul', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
console.log(localeString.replace(' ', '').replace('-', '').replace(':', '').replace('.', '').replace('/', '').replace('년', '').replace('월', '').replace('일', '').replace('시', '').replace('분', '').replace('초', ''));
이 코드는 현재 날짜와 시간을 한국 시간대에 맞게 '년월일시간분초' 형식으로 변환합니다.
이러한 방법들을 사용하여 날짜를 로컬 형식으로 문자열로 변환할 수 있습니다.
2025-08-10 20:07