RangeError: invalid date

๋ฉ”์‹œ์ง€

RangeError: invalid date (Firefox)
RangeError: invalid time value (Chrome)
RangeError: Provided date is not in valid range (Chrome)

์—๋Ÿฌ ์ข…๋ฅ˜

RangeError

๋ฌด์—‡์ด ์ž˜๋ชป ๋œ ๊ฑธ๊นŒ?

์œ ํšจํ•˜์ง€ ์•Š์€ String์ด Date ๋‚˜ Date.parse()์— ์ž…๋ ฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์‹œ

์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์€ ์‚ฌ์šฉ ์˜ˆ์‹œ

์ธ์‹ ํ•  ์ˆ˜ ์—†๋Š” string์ด๋‚˜ ์ž˜๋ชป๋œ ์š”์†Œ ๊ฐ’์„ ํฌํ•จํ•˜๋Š” ISO ํ˜•์‹์˜ ๋‚ ์งœ string์€ ์ผ๋ฐ˜์ ์œผ๋กœ NaN์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๊ตฌํ˜„ ๋ฐฉ์‹์— ๋”ฐ๋ผ ISO ํ˜•์‹ string์„ ๋”ฐ๋ฅด์ง€ ์•Š๋Š” ๊ฒฝ์šฐ RangeError: invalid date๊ฐ€ ํ‘œ์‹œ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Firefox์˜ ๊ฒฝ์šฐ:

new Date('foo-bar 2014');
new Date('2014-25-23').toISOString();
new Date('foo-bar 2014').toString();

๊ทธ๋Ÿฌ๋‚˜ ์ด ๊ฒฝ์šฐ, Firefox์—์„œ๋Š” NaN ์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค:

Date.parse('foo-bar 2014'); // NaN

๋” ์ž์„ธํ•œ ์‚ฌํ•ญ์€  Date.parse() ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.

์˜ฌ๋ฐ”๋ฅธ ์‚ฌ์šฉ ์˜ˆ์‹œ

new Date('05 October 2011 14:48 UTC');

๋” ๋ณด๊ธฐ