728x90
반응형
1) 원하는 형태로 조정
const now = new Date(); // create a new Date object with the current date and time
const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, '0'); // add 1 to the month (since getMonth() returns a zero-based index) and pad with leading zero if necessary
const day = now.getDate().toString().padStart(2, '0'); // pad with leading zero if necessary
const hour = now.getHours().toString().padStart(2, '0'); // pad with leading zero if necessary
const minute = now.getMinutes().toString().padStart(2, '0'); // pad with leading zero if necessary
const second = now.getSeconds().toString().padStart(2, '0'); // pad with leading zero if necessary
const formattedDate = `${year}/${month}/${day} ${hour}:${minute}:${second}`;
console.log(formattedDate); // Output: "2023/04/07 11:20:35"
* 하루 더한 날짜 구하기
let tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() +1);
2) toLocaleString 이용
let tomorrow = new Date();
new_tomorrow = tomorrow.toLocaleString(
'ko-KR',
{
timeZone: 'Asia/Seoul',
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', second: '2-digit',
hour12: false
}
);
728x90
반응형
'Javascript' 카테고리의 다른 글
Javascript: slide # 무한 슬라이드 (0) | 2023.09.10 |
---|---|
Javascript: Parsing HTML #select #checkbox #radio (0) | 2023.03.31 |
javascript: event.target vs event.currentTarget (0) | 2023.03.09 |
주소 API # 행정안전부 # javascript # ajax # xml (0) | 2023.03.08 |
Javascript 이미지 업로드 미리보기 (0) | 2023.02.24 |