Programming/JavaScript

[JavaScript] ν•œλ‹¬ μ „/ν›„ λ‚ μ§œ κ΅¬ν•˜κΈ°

yuri lee 2022. 10. 1. 14:41
λ°˜μ‘ν˜•

Intro

JavaScript μ—μ„œ ν˜„μž¬ μ‹œκ°„μ„ κΈ°μ€€μœΌλ‘œ ν•œλ‹¬ μ „/ν›„ λ‚ μ§œλ₯Ό κ΅¬ν•˜λŠ” 방법에 λŒ€ν•΄ μ•Œμ•„λ³΄λ„λ‘ ν•˜κ² μŠ΅λ‹ˆλ‹€. 

 

How to solve the problem

let now = new Date();	// ν˜„μž¬ λ‚ μ§œ 및 μ‹œκ°„
console.log("ν˜„μž¬ : ", now); // ν˜„μž¬ :  Fri Sep 30 2022 11:05:32 GMT+0900 (ν•œκ΅­ ν‘œμ€€μ‹œ)
let oneMonthAgo = new Date(now.setMonth(now.getMonth() - 1));	// ν•œλ‹¬ μ „
console.log("ν•œλ‹¬ μ „ : ", oneMonthAgo); // ν•œλ‹¬ μ „ :  Tue Aug 30 2022 11:05:32 GMT+0900 (ν•œκ΅­ ν‘œμ€€μ‹œ)

let now = new Date();	// ν˜„μž¬ λ‚ μ§œ 및 μ‹œκ°„
console.log("ν˜„μž¬ : ", now);
let oneMonthLater = new Date(now.setMonth(now.getMonth() + 1));	// ν•œλ‹¬ ν›„
console.log("ν•œλ‹¬ ν›„ : ", oneMonthLater);
λ°˜μ‘ν˜•