TE
테크에코
홈24시간 인기최신베스트질문쇼채용
GitHubTwitter
홈

테크에코

Next.js로 구축된 기술 뉴스 플랫폼으로 글로벌 기술 뉴스와 토론을 제공합니다.

GitHubTwitter

홈

홈최신베스트질문쇼채용

리소스

HackerNews API원본 HackerNewsNext.js

© 2025 테크에코. 모든 권리 보유.

Why are 2025/05/28 and 2025-05-28 different days in JavaScript?

140 포인트작성자: brandon_bot2일 전

18 comments

Y_Y2일 전
Hang on, slashes and year-month-day?<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;ISO_8601" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;ISO_8601</a><p>Handed down by the ISO, The Great Compromise allows YYYY-MM-DD (or YYYYMMDD if you&#x27;re in a hurry) but the version with slashes I&#x27;d find ambiguous and upsetting, especially early in the month.<p>The standard is good, and you can get it from `date -I`. Hell mend anyone who messes with the delimiters or writes the year in octal or any other heresy.
评论 #44113619 未加载
评论 #44113841 未加载
评论 #44115774 未加载
评论 #44115304 未加载
PokerFacowaty2일 전
I recently spent 2 hours on finding the bug, precisely because JS can&#x27;t comprehend dates&#x2F;times without a Unix timestamp underneath. I&#x27;d take a date from Postgres as e.x. &quot;2025-05-24&quot; and the first time somewhere deep in the package I was using, when JS encountered that, it needed to add a time (midnight, that&#x27;s sane) and timezone (local time :) ). I was trying to use UTC everywhere and since the read dates had midnight of UTC+2 as the time, they were all a day behind in UTC.<p>Special shoutouts to the author of node-postgres saying the PG&#x27;s date type is better not used for dates in this case.[1] I love programming.<p>[1] <a href="https:&#x2F;&#x2F;node-postgres.com&#x2F;features&#x2F;types#date--timestamp--timestamptz" rel="nofollow">https:&#x2F;&#x2F;node-postgres.com&#x2F;features&#x2F;types#date--timestamp--ti...</a>
评论 #44114047 未加载
bandrami2일 전
How did they manage to build the entire modern Web on a language without a standard library?
评论 #44113945 未加载
评论 #44113796 未加载
评论 #44113589 未加载
评论 #44113601 未加载
评论 #44115656 未加载
评论 #44115387 未加载
评论 #44113695 未加载
评论 #44115693 未加载
评论 #44113721 未加载
评论 #44114516 未加载
mrweasel2일 전
Dates in JavaScript is just a special kind of broken. Even with the more modern APIs for formatting dates it&#x27;s just wonky at best.
thrdbndndn2일 전
After carefully reading the timeline, I think the most surprising part is that when Chrome switched again to defaulting to local time for date-only forms in 2015 (together with date-time form), someone complained it was a &quot;breaking change&quot;, despite the fact that it was simply following the spec, and it even went so far that it eventually caused the spec itself to change, and now we’re stuck with the Frankenstein mess we have today.<p>By that, I don&#x27;t mean to dismiss the importance of backward compatibility, but this case is particularly funny because:<p>1. It had already been changed multiple times, each a breaking change, so it’s not like this form of compatibility was ever seriously respected;<p>2. Having it behave differently from other &quot;legacy forms,&quot; like the slash-separated version, is itself arguably a break in backward compatibility;<p>3. As noted in the article, it never worked the same between Chrome and Firefox (at this point) anyway, so it’s doubtful how impactful this &quot;breaking change&quot; really was, considering you already had to write shim code either way.
nordiknomad52일 전
I am not sure why my brave browser does not console out the error as in the OP<p>console.log(new Date(&#x27;2025&#x2F;05&#x2F;28&#x27;).toDateString());<p>console.log(new Date(&#x27;2025-05-28&#x27;).toDateString());<p>console.log(new Date(&#x27;2025-5-28&#x27;).toDateString());<p>OutPut Below<p>Wed May 28 2025 debugger eval code:1:9 Wed May 28 2025 debugger eval code:2:9 Wed May 28 2025 debugger eval code:4:9
评论 #44114786 未加载
vladde2일 전
In Sweden, we can write dates as 28&#x2F;5-25
评论 #44113832 未加载
评论 #44113803 未加载
评论 #44113748 未加载
评论 #44113835 未加载
评论 #44113867 未加载
评论 #44113963 未加载
fimdomeio2일 전
On a broader note for the ones out there not familiar with this &quot;timeless&quot; classic:<p>Falsehoods programmers believe about time gist.github.com&#x2F;timvisee&#x2F;fcda9bbdff88d45cc9061606b4b923ca
lifthrasiir2일 전
Ah, usual issues with any old enough language with multiple popular implementations. Enjoy your standards. (At least ECMAScript is a relatively well-thought standard...)
pif2일 전
I&#x27;m missing the usual suspects complaining about how browsers exploit undefined behaviour and break programmers&#x27; expectations.
alex-knyaz2일 전
What are best practices&#x2F;tips on handling date and time everyone has in general? Every time it is a bit of a nightmare.
评论 #44115207 未加载
评论 #44114951 未加载
divan2일 전
WAT [1]<p>[1] <a href="https:&#x2F;&#x2F;www.destroyallsoftware.com&#x2F;talks&#x2F;wat" rel="nofollow">https:&#x2F;&#x2F;www.destroyallsoftware.com&#x2F;talks&#x2F;wat</a>
评论 #44113929 未加载
stevoski2일 전
I find it fascinating that JavaScript has so many &quot;WTF?&quot; things like this, and yet is so incredibly successful.<p>Being available everywhere (as far as browsers are concerned) trumps almost all other factors.
评论 #44115463 未加载
Havoc2일 전
No idea but it makes perfect sense that the question is about JavaScript
Lev1a2일 전
Obligatory:<p><a href="https:&#x2F;&#x2F;www.destroyallsoftware.com&#x2F;talks&#x2F;wat" rel="nofollow">https:&#x2F;&#x2F;www.destroyallsoftware.com&#x2F;talks&#x2F;wat</a>
评论 #44114789 未加载
HenryBemis2일 전
2020-04-23 16:36 is the date and time (as listed in my Bookmark Manager) that I bookmarked this [0] to my Firefox browser.<p>[0]: <a href="https:&#x2F;&#x2F;xkcd.com&#x2F;1179&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xkcd.com&#x2F;1179&#x2F;</a>
animanoir2일 전
I wish we could move on from this trash already.
pif2일 전
Undocumented Undefined Behaviour, anyone?
评论 #44113910 未加载