Wireframe

자바 스크립트 날짜 계산 방법

자바스크립트에서 날짜 계산하기. 흔하게 사용하는 것인데 잠깐 생각이 안나서 메모.

두 날짜의 차이

날짜 객체를 빼면 밀리세컨드 값이 나온다.

var a = new Date(2014, 4, 10);
var b = new Date(2014, 4, 12);
var c = b - a;
console.log(c/(24 * 3600 * 1000));

몇일 전 혹은 몇일 후 구하기

var today = new Date();
today.setDate(today.getDate() + 3);
console.log(today.toLocaleString());
Exit mobile version