15.6 날짜 데이터 전송하기

  • 자바스크립트의 Date 인스턴스는 날짜를 저장할 때 UTC 기준으로 유닉스 타임스탬프를 저장

  • 자바스크립트에서 날짜를 전송하는 가장 확실한 방법 => JSON

const before = { d: new Date() };
before.d instanceof Date // true
const json = JSON.stringify(before);
const after = JSON.parse(json);
after.d instanceof Date // false
typeof after.d // "string"

after.d = new Date(after.d); // 사용자의 타임존 기준으로 표시
after.d instanceof Data // true

Last updated