it leader
article thumbnail

 

*오늘 날짜 구하기

var today = new Date();

// 2021-02-19
console.log("today : "  + today) ==> Feb 19 2021 00:00:00 GMT+0827(대한민국 표준시)

 

*어제 날짜 구하기

//2020-02-19
var today = new Date();
var yesterday = new Date(today.setDate(today.getDate() - 1));

console.log("yesterday : " + yesterday ) 
// Feb 18 2021 00:00:00 GMT+0827( 대한민국 표준시 )

 

* 내일 날짜 구하기

//2020-02-19
var today = new Date();
var tomorrow = new Date(today.setDate(today.getDate() + 1));

console.log("tomorrow : " + tomorrow ) 
// Feb 20 2021 00:00:00 GMT+0827( 대한민국 표준시 )

 

*한달전, 일년전 날짜 구하기

//2020-02-19
var today = new Date();
var monthAgo = new Date(today.setDate(today.getMonth() - 1));

console.log("monthAgo : " + monthAgo ) 
// Jan 19 2021 00:00:00 GMT+0827( 대한민국 표준시 )

var yearAgo = new Date(today.setDate(today.getYear() - 1));

console.log("yearAgo : " + yearAgo ) 
// Feb 19 2020 00:00:00 GMT+0827( 대한민국 표준시 )

 

profile

it leader

@dev__pixui

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!