JavaScript Date의 toString()을 믿어야 하나

YI Eun Gook·2020년 1월 2일
1

1줄 요약: 믿지 말자;

ECMAScript 8판(2017년)의 언어 명세를 보면, 이렇게 되어 있다.

Return an implementation-dependent String value that represents tv as a date and time in the current time zone using a convenient, human-readable form.

ㅇㅁㅇ

눈을 씻고 다시 봐도 convenient, human-readable form 이라고 되어 있는 것;
ECMAScript 9판(2018년)의 언어 명세부터는 구체적으로 정의되어 있으니, es9가 보장된 환경에서는 믿고 사용해도 될 듯

대안으로는..

  1. Moment.js
  2. Date.prototype.getDate() 등으로 toString()을 직접 구현하기
profile
= v =?;;

0개의 댓글