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

137 brandon_bot 144 5/28/2025, 7:09:31 AM brandondong.github.io ↗

Comments (144)

Y_Y · 1d ago
Hang on, slashes and year-month-day?

https://en.wikipedia.org/wiki/ISO_8601

Handed down by the ISO, The Great Compromise allows YYYY-MM-DD (or YYYYMMDD if you're in a hurry) but the version with slashes I'd find ambiguous and upsetting, especially early in the month.

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.

tluse · 1d ago
Pro tip: never ever use anything but ISO dates in UTC tz unless you're displaying it for a user in a UI.
names_are_hard · 1d ago
What if you're storing a calendar date, such as a birthday? A timestamp is inappropriate, and it's meaningless to discuss timezones in this context.

(Example - you want to know if a person is old enough to buy cigarettes, and you need to store a birthday that you can compare against the current day to see if they're legally 18 - if you store an epoch at UTC, do you store the time of day they were born? That's not the way the law works. Do you store midnight UTC? If they're currently in NY, can they but cigarettes at 7pm the day before their birthday because they're currently 18 in London?)

Sometimes you need a logical calendar date, not a point in time in the history of the universe.

guffins · 22h ago
That’s a great question. ISO 8601 doesn’t allow timezone offsets on date-only strings.

If you were born in the US, can you buy cigarettes at 12:00 am on your 18th birthday in London?

I’ve never heard of age verification laws caring what timezone you were born in. In fact, you couldn’t even pinpoint this from many people’s ID cards. Plenty of US states span multiple time zones, and I wouldn’t be that surprised if there were a maternity ward out there sitting on a TZ line.

ezfe · 22h ago
Simple answer is no, since your ID doesn’t have a time zone of birth on it, they have to read it as local time.
atoav · 20h ago
The answer is that no age related verification-problem in real world is so sensitive that a day plus or minus would make any difference. So they skip the entire clusterfuck of a problem of timezones by just ignoring them.

I grew up in a country where you could legally buy beer with 16 and and hard alcohol with 18. So if the answer to "when should someone be allowed to choose to drink alcohol" has a variance of multiple years between countries who cares about a day or two.

rubslopes · 1d ago
All solutions have problems, but I think UTC midnight is simpler than dealing with mixed date formats in the backend.
ivan_gammel · 23h ago
It’s 2025 and major backend stacks have domain-specific time types like LocalDate etc. Using them is the only correct and actually the simplest solution.
mytailorisrich · 22h ago
If you want to store a date you don't need to store a time, time zone, etc. and your question goes away.

Certainly if you want to store birth dates and do age verification there is no point bothering with these issues, just store calendar date. Trivial to get date for age limit purposes.

fnord123 · 1d ago
RFC3339.

ISO 8601 allows for 2 or 6 digit years. Truncating to 2 is just incorrect, and 6 digits is absurd. And you can read the RFC without paying ISO - and you can discuss the RFC with people who have also read it instead of relying on people using the Wikipedia page to interpret and explain ISO 8601.

I have a scheduling service at work and I keep getting requests for implementing ISO 8601 timestamps but I ignore them. RFC3339 is the way forward.

jcul · 1d ago
There's this handy venn diagram that I've seen floating around for a long time.

Just found a random link to it with an image search:

https://gyazo.com/d8517f72e24c38f055e17182842b991c/max_size/...

ISO 8601 does have some strange formats...

badmintonbaseba · 1d ago
That's a screenshot of this website:

https://ijmacd.github.io/rfc3339-iso8601/

skissane · 1d ago
> ISO 8601 does have some strange formats...

Not that I’ve ever really had cause to use it in anger, but I like the idea of ISO week dates.

Effectively, the ISO weak year (often differs from the calendar year in the last week of December / first week of January), ISO week number and day of week form a leap week calendar - instead of having 365 days in a common year and 366 in a leap year, it has 364 days in a common year and 371 in a leap week year, with leap weeks (obviously) being less frequent than leap days.

The Sym454 calendar [0] takes this idea further to create a perpetual calendar, with 12 months of 4 or 5 weeks; in leap years the 12th month is 5 weeks instead of 4 weeks long. However, the leap week rule proposed by Sym454 is different from that proposed by ISO 8601; the author of Sym454 argues his proposed rule has theoretical advantages (simple calculation and more uniform distribution of leap weeks). That said, there is a variant of Sym454 which uses the ISO 8601 leap week rule.

[0] https://kalendis.free.nf/symmetry.htm?i=1

Y_Y · 1d ago
I believe two-digit years haven't been allowed for a while:

> ISO 8601:2000 allowed truncation (by agreement), where leading components of a date or time are omitted. Notably, this allowed two-digit years to be used as well as the ambiguous formats YY-MM-DD and YYMMDD. This provision was removed in ISO 8601:2004.

(That's from https://en.wikipedia.org/wiki/ISO_8601 - I don't have the standards handy, ironically.)

Honestly I'm happy with either the RFC or ISO, but it seems like most normies haven't heard of RFCs so ISO is my default.

fnord123 · 21h ago
I believe you. But I haven't paid ISO for the pleasure of reading the actual spec so that passed me by.
account42 · 1d ago
Plus RFC3339 allows you to use a space instead of the ugly T delimiter between the date and time.
realaleris149 · 16h ago
> 6 digit years

Totally insufficient for capturing important future events like the dead of the sun.

nssnsjsjsjs · 1d ago
And unless you need the original date, time and time zone.

Conversion to UTC is not injective e.g. when clocks change or politics happen

No comments yet

davejohnclark · 22h ago
There's a good post about why this isn't as foolproof an approach as it might first seem here https://codeblog.jonskeet.uk/2019/03/27/storing-utc-is-not-a...
christina97 · 22h ago
The post doesn’t account for the case where a suburb of Amsterdam breaks off from the rest of Netherlands and changes timezones… Then how do you know if the event was in the neighborhood or not?

My point is that this is an extremely niche case and works around one particular type of timezone insanity. You either have a team dedicated to dealing with timezone insanity, or you store stuff in UTC.

mzl · 22h ago
No, but that is an even less likely situation, compared to the problems that the approach advocated for by Jon Skeet actually solves.
sph · 1d ago
Pro tip #2: never ever rely on automatic parsing of dates. It's a lie and will corrupt your data.

Either use dedicated "from_iso8601" functions, or manually specify the format of the input string ("%Y%m%dT%H%M%SZ")

j1elo · 3h ago
The list of things that devs should "never ever" do grows by the day... turns out most things, even the simplest of things, even sometimes the most apparently trivial things (like naming of people, too) are in reality almost always much more complex and difficult to get right on the first go than expected.

But then discussion ensues about how programmers these days add libraries as dependencies for almost everything! :-)

I guess at some point a middle ground must be found.

dotancohen · 23h ago

  > never ever use anything but ISO dates in UTC tz unless you're displaying it for a user in a UI.
Not good for storing future meeting times. DST switchover dates can change, and your tz-normalized date won't change with it.
saltcured · 18h ago
Or if you really want to be future proof, store the geolocation so you can try to figure out the jurisdiction for any changing regulations. Maybe they didn't change the date of the switch, but changed the timezone boundary on the map.

But, then I guess we might need to account for fractured societies and actually store some kind of organizational code for which belief system the event author adheres to? :-)

dotancohen · 14h ago
You jest, but there are three calendars in active daily use in close enough proximity to me that it is not unheard of for mistakes to happen. Especially in the evening, as not all calendars start the new day at the same hour!
mytailorisrich · 22h ago
To me that an UI/UX issue.

Internally everything is stored and handled in TAI (better than UTC as no discontinuity) and translated from/to something else for human consumption.

I.e. for instance your should have logic to figure out what TAI period corresponds to "next month's meetings" if that's what the user wants, which you apply immediately on user inputs and then forget about DST, time zones, etc. in the rest of the code and storage.

Another benefit is that if your user was in New York but is now in London it is trivial and well-constrained to adjust to local time.

mzl · 22h ago
No, it is not. It is because converting to UTC loses information that can't be retrieved.

No comments yet

ezfe · 22h ago
Uh, no - meetings need to be stored with a timezone they were created in. This is how major calendar apps work.

In Apple Calendar you can enable advanced timezone settings and you get a timezone override option.

No comments yet

Scarblac · 1d ago
I disagree, store UTC time and the name of timezone it was originally recorded in so it can be translated back to that as well.

UTC only loses information.

skissane · 1d ago
> and the name of timezone

The problem is that can be difficult to portably determine. One wishes POSIX had an API “give me IANA time zone name for current process” which would do the needful to work it out (read TZ environment variable, readlink /etc/localtime, whatever else might be necessary)… but no, you are left to do those steps yourself. And it works reasonably well if the TZ environment variable is set, but it most commonly isn’t; readlink of /etc/localtime works on macOS and some Linux distros… but others make /etc/localtime a regular file not a symlink, which makes it all a lot harder

And that’s POSIX. Then there’s Windows which is possibly the last platform to still use its own timezone database instead of IANA’s. Now, Unicode CLDR maintains a Windows-to-IANA mapping table… but you have to ship both that table, and maybe the IANA timezone DB too, with your app, and keep them updated

I really wish Microsoft would ship the IANA database with Windows, and the IANA-Windows mapping table too, and provide APIs to query them, and keep them updated with Windows update. The core Windows OS and existing Windows apps can keep on using the legacy Windows TZ database for backward compatibility, whereas portable apps could use IANA instead if they wish

tatersolid · 6m ago
> I really wish Microsoft would ship the IANA database with Windows, and the IANA-Windows mapping table too, and provide APIs to query them, and keep them updated with Windows update.

I think they have done exactly what you describe for several years at least:

https://learn.microsoft.com/en-us/dotnet/api/system.timezone...

mariusor · 1d ago
Why not store it as a time date in the original timezone then?
FrancoisBosun · 23h ago
You still need the timezone name to map back to UTC, in case you want to make some types of computations, usually along the lines of "how long ago was this" and "remaining time until this thing happens".

You may argue that we can use local time to make the computations and be done with it, but during DST transitions, local time jumps so the number of actual seconds won't be consistent.

jgalt212 · 1d ago
Yes, but whose timezone? The machine? The user? What about a machine to machine transaction?
hughw · 23h ago
Some use cases really do require the local TZ offset be saved. Transforming everything to UTC wipes out that information.

An engineer in the US reviewing industrial measurements logged in a plant in Asia from a variety of sources is definitely going to encounter lots of events recorded in local time. It would be maddening for that engineer to have to review and resolve events from different time coordinates, especially if they are doing the review months or years later. It's best to accept that reality and adopt local time as the standard. Then you must record the TZ offset per UTC in any new system you create.

bbojan · 22h ago
You mean you must record the timezone? Because the TZ offset can change throughout the year (e.g. due to daylight saving time).
hughw · 22h ago
Usually the TZ offset is enough. The use case is a guy reading notes and logs from multiple sources. All that guy needs is to see the local time at the time and place of the event. So that, for example, he can match up the time stamp on some computer recorded log with the time some human operator recorded, in local time, on a paper record.
ulrikrasmussen · 1d ago
And if you need a date, then represent it as a date and not as a time point.
xiconfjs · 1d ago
Even then it‘s ok :)
0points · 1d ago
Proer tip: never use anything but unix timestamp until presentation.
alexey-salmin · 1d ago
There's no reliable way to map it back into the local time in the past, unless you also safe the UTC offset.
ryao · 1d ago
If you record them with some known UTC offset regardless of localtime (e.g. 0), you can convert to local time in the past.
isleyaardvark · 23h ago
The problem with that is you lose the localtime information, which you may want. Say you have recorded the localtime with the known UTC offset of 0, and that localtime is midnight UTC. Now you want to map it back to a localtime in the past. Ok, which localtime? Was it 8pm in NYC? Or was it 5pm in LA? Is the assumption that the localtime is wherever the user is right now, and is that a valid assumption? If the user has traveled to a different timezone, the time is now being converted to a localtime in the past that is different than it actually was when it happened.

edit: another commenter shared this link with an example: https://codeblog.jonskeet.uk/2019/03/27/storing-utc-is-not-a...

I like their "Principle of preserving supplied data".

ainiriand · 1d ago
Even more proer tip: only use binary representations of variables until presented to the user.
globular-toast · 1d ago
This is great until someone asks whether a particular event happened before or after lunch.
ryao · 1d ago
I always felt the answer to this question is both, since there is always yesterday and tomorrow as far as lunch is concerned, so everything by definition is both before and after lunch. Perhaps the question is ill formed and needs to ask if the time was before, during or after lunch, during the day of the timestamp while defining what during means. That would have a more normal answer.
IAmBroom · 20h ago
The question is clear.

You are obfuscating it, for your own entertainment.

atoav · 20h ago
And ifnyou're displaying it in the Ui give users a date format option where ISO is the choice.

I use ISO for everything and your software wrongly assuming I want a deranged lunatic date format based on some locale is not going to cut it.

Locale is ok as a first guess, but maybe allow users tho make that choice?

mytailorisrich · 22h ago
TAI is even better as it is continuous without leap seconds.
thrdbndndn · 1d ago
How is slashes ambiguous if you use YYYY and in YMD order?
shreddit · 1d ago
Because Americans use slashes commonly in Y/D/M
skissane · 1d ago
YDM is very rare; according to Wikipedia, only found in Kazakhstan, Latvia, Nepal, and Turkmenistan, and even in those countries it commonly coexists with other formats.

I believe internationally that YMD and DMY are the two most common formats (and also the most logical), and the (much less logical) MDY comes third… YDM is a very distant fourth. MYD, DYM are theoretically possible but doubt anybody uses them

Actually, although MDY is by far most common in the US, I’ve seen US federal government forms that use DMY instead (although I imagine that’s rare, I’m sure you’ll find DMY US govt forms are greatly outnumbered by MDY ones)

madcaptenor · 22h ago
I can't even see how someone could get to a format with the year in the middle. In uses where you don't need to specify the year you might use either MD or DM, and when adding the year you could put Y either on the front or back of either of those.
shreddit · 1d ago
My apologies to all Americans, of course i meant M/D/Y, i just got it backwards
thrdbndndn · 1d ago
I'm not American but I lived in the US for 10 years.

I had never seen Y/D/M. I almost never see American use Day/Month order to begin with, let alone Y/D/M.

binarymax · 1d ago
No we don’t. I’m American and I’ve never seen this format.
hnbad · 1d ago
Wait, I thought Americans use M/D/Y not Y/D/M?
chungy · 1d ago
This is correct, the most common short-hand format in America is MM/DD/YYYY (possibly two digits in the last group). Dates like 05/28/2025 and 28/05/2025 are unambiguous enough to deal with order differences, dates like 06/03/2025 are not.

Year first and dashes is pretty much exclusively YYYY-MM-DD, no ambiguity; 2025-03-06 cannot be interpreted in any manner other than "the sixth day of the third month of the year 2025"

silisili · 1d ago
We do, almost exclusively.

We'll use Y/M/D for systems or ordering, sometimes.

I can't recall having ever seen Y/D/M used in any notable sense.

apricot · 9h ago
OP is probably little-endian.
kace91 · 1d ago
Uh, TIL. As a non American it was known to me that Americans use the YDM format but I had no idea slashes vs dashes carried meaning for that.
thrdbndndn · 1d ago
Do they? I think the US use MDY mostly and sometimes YMD.
floydnoel · 1d ago
they don’t really, at least not in any universal sense. in the military (marine corps) we always used YMD with slashes. i would say that in non-military contexts, dashes are seen with YMD more frequently. but dashes or slashes are used for both YMD and MDY and there's no legal rule or regulation nor requirement to use one or the other. some people just pattern match quickly and assume too much based on that.
jfindley · 22h ago
The standard is... well, it IS indeed a standard, I guess you can't really argue that, but it's a very great deal more permissive than many people might hope or expect. https://ijmacd.github.io/rfc3339-iso8601/ is a wonderful illustration of some of the deeply silly time formats permitted by ISO 8601.
dghf · 23h ago
> Hang on, slashes and year-month-day?

I believe slashes are the most common separators in Japan (which uses that order), at least when explicit kanji for "year", "month" and "day" aren't used.

pezezin · 7h ago
Periods as separators are also quite common.
PokerFacowaty · 1d ago
I recently spent 2 hours on finding the bug, precisely because JS can't comprehend dates/times without a Unix timestamp underneath. I'd take a date from Postgres as e.x. "2025-05-24" and the first time somewhere deep in the package I was using, when JS encountered that, it needed to add a time (midnight, that'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.

Special shoutouts to the author of node-postgres saying the PG's date type is better not used for dates in this case.[1] I love programming.

[1] https://node-postgres.com/features/types#date--timestamp--ti...

normie3000 · 1d ago
> it needed to add a time (midnight, that's sane)

Is it sane? Is midnight at the start of a day, or the end of it? I'd think noon would be less ambiguous, and significantly less prone to these timezone issues (although this may not be a benefit).

kccqzy · 22h ago
Indeed it is not sane. Languages should provide a separate Day type to operate on dates without times. Forcing everything to use dates with times and timezones causes bugs in applications that don't need times.
dumah · 1d ago
ISO 8601-1:2019/Amd 1:2022

Midnight at the start of the day: 00:00:00

Midnight at the end of the day: 24:00:00

bandrami · 1d ago
How did they manage to build the entire modern Web on a language without a standard library?
jasode · 1d ago
> on a language without a standard library?

Because the other languages & with bigger runtimes and more comprehensive standard libraries such as Java applets, Microsoft Silverlight, Macromedia Flash that were promoted for browsers to create "rich fat clients" were ultimately rejected for various reasons. The plugins had performance problems, security problems, browser crashes, etc.

Java applets was positioned by Sun & Netscape to be the "serious professional" language. Javascript was intended to be the "toy" language.

In 1999, Microsoft added XMLHttpRequest() to IE's Javascript engine to enable Outlook-for-web email that acted dynamically like Outlook-on-desktop without page refreshes. Other browsers copied that. (We described the early "web apps" with jargon such as "DHTML" DynamicHTML and "AJAX".) In 2004, Google further proved out Javascript capabilities for "rich interactive clients" with Gmail and Google Maps. Smoothly drag map tiles around and zooming in and out without Macromedia Flash. Even without any deliberate coordinated agenda, the industry collectively begins to turn Javascript from a toy language into the dominant language for all serious web apps. Javascript now had huge momentum. A language runtime being built into the browser without a standard library like Javascript was prioritized by the industry more than the other options like plugins that had a bigger "batteries included" library. This overwhelming industry preference for Javascript happened before Node.js for server-side apps in 2009 and before Steve Jobs supposedly killed Flash in 2010.

The situation today of Node.js devs using npm to download "leftpad()" and a hundred other dependencies to "fill in the gaps" of basic functionality comes from the history of Javascript's adoption.

normie3000 · 1d ago
> other languages & with bigger runtimes and more comprehensive standard libraries such as Java

Java's Date standard lib was awful for 2 decades, so there's no guarantee that a big standard library is a good standard library.

sethammons · 1d ago
Even in a good standard library, oddities arise. Many praise Go for its standard library but then there is its time format that raises an eyebrow: 01/02 03:04:05PM '06 -0700
pezezin · 7h ago
Much like the traditional Unix date format, which for some reason puts the year at the end. Example from my computer:

$ date

Thu 29 May 13:12:30 JST 2025

throwaway2037 · 1d ago
I agree 100%. Thank goodness that Stephen Colbourne's JodaTime and later JSR-310 fixed all of that. The new date/time libraries are dream in Java.
yen223 · 1d ago
The world where JavaScript has a robust standard library is one where there is only one browser vendor who gets to call all the shots regarding what the web looks like.

That is not a better world.

cjpearson · 1d ago
Possibly, although the fix for this particular issue (Temporal API) is available in the current release of Firefox as well as the preview release of Safari, but it's not in that dominant browser.
Xelbair · 1d ago
and that differs from chrome dictating standards how?

also this could've been handled easily by committee(ugh), or a 3rd party open source organization akin to linux foundation that just makes js library that all browser vendors use. Or making just a specification for JS handling things.

you know - like a lot of other languages are handled, including their standard library.

h4ck_th3_pl4n3t · 1d ago
Kind of funny that you think the open web still exists.

I mean, even Microsoft gave up and just went with Chromium, and they got the definition of almost infinite resources at their disposal.

Effectively if your website doesn't run in Chrome and Safari, it won't be seen by 99% of the market.

0points · 1d ago
> even Microsoft gave up

Ah yes, Microsoft, the defenders of the free world.

oarsinsync · 1d ago
> > even Microsoft gave up ... and they got the definition of almost infinite resources at their disposal

> Ah yes, Microsoft, the defenders of the free world.

No, Microsoft, one of the few businesses in the world that has both the technical ability, and the financial muscle, to be able to develop their own browser engine.

Who still chose not to. Leaving us stuck in the duopoly of Apple and Google, even outside of our mobile phones.

arcanemachiner · 1d ago
Embrace

Extend

Enhance the world's beauty

Y_Y · 1d ago
> That is not a better world.

Not a better world, just the current world.

aloha2436 · 1d ago
Safari is too valuable of a platform for web developers to ignore, but otherwise yes it's the only real exception to the Chrome monopoly and still certainly much smaller in terms of absolute users.
dotancohen · 23h ago
I use Firefox on all my devices.
nomdep · 22h ago
Mozilla is no longer a better actor than Google or Apple, just smaller
johncoltrane · 1d ago
I want that world.
baq · 1d ago
Actually it is. Sorry.
Y_Y · 1d ago
There's even worse language language for this. It's absolutely essential for an modern e-commerce, but has no official standard or spec, many thousands of libraries but they're mostly poorly maintained and geoblocked. The language itself is just a hodge podge of other languages that were popular in the past, and as a result it's worse than Perl for having too many ways to do any single thing. The major dialects may be theoretically compatible, but in practice there's usually friction when you try to mix them.

[Ok that's enough, ed.]

VoidWhisperer · 1d ago
PHP?
Y_Y · 1d ago
Rather than spoil this tremendous piece of humour, I'll just give a rot13-encrypted version of the answer: Ratyvfu
IAmBroom · 20h ago
That's hardly unique to Ratyvfu. Nyy languages do that.
bandrami · 22h ago
Since I'm here, one of my standard interview questions when I'm hiring is "how would you convert a Gregorian date to a Julian date?" (and I make clear there's no penalty for not knowing those terms, and explain them if needed.)

What I'm looking for is "there has to be a library function for that; I would look it up".

omneity · 1d ago
With a lot of motivation, grit, coffee and reinventing the wheel every couple of weeks.
crubier · 22h ago
An interesting related question could be: Why did all languages with standard libraries fail to become the lingua franca of the Web against JavaScript?
HPsquared · 22h ago
Path dependence. JS was in the browser.
hnbad · 1d ago
Because the alternative would have been VBScript (if Microsoft had won at the time).

JS was a compromise. It had to be sent out the door quick, it needed to look sufficiently like Java to not upset Sun who were trying to establish Java as the universal platform at the time while not being feature complete enough to be perceived as a competitor rather than a supplement. And it had to be standardized ASAP to pre-empt Microsoft's Embrace Extend Extinguish strategy (which was well on its way with JScript). That's also why it's an ECMA standard rather than ISO despite Netscape not having been based in Switzerland - ECMA simply offered the shortest timeline to publishing a standard.

I think what's more amazing isn't just how we managed to build the bulk of user interfaces in JavaScript but how we Node.js managed to succeed with ECMAScript 3. Node.js was born into a world without strict mode and without even built-in support for JSON: https://codelucky.com/javascript-es5/ - and yeah, ECMAScript 3 was succeeded by ECMAScript 5 not 4 because it took vendors 10 years to agree on how the language should evolve in the 21st century - not only did we build the modern web on JavaScript, we built a lot of the modern web on the version of JavaScript as it was in 1999! Even AJAX wasn't standardized until 2006 when Web 2.0 was already in full swing.

AlienRobot · 23h ago
It's called a web because of how it's held together.
dotancohen · 23h ago
It's called a web because it's full of bugs.
cjpearson · 1d ago
The same way people are replacing C++ on a language without a standard library
augusto-moura · 1d ago
What? JavaScript _has_ a standard library. And even though it has a lot of legacy baggage, it is very well defined [1] [2]. Much better defined than C, for example, where a lot of undefined behavior is given as common practice, but in reality is up to compiler implementation, and varies from architecture to architecture.

JavaScript even with all its thorns, it's a very consistent ecosystem nowadays, across browsers and architectures. Being forever retro-compatible is a good thing, meaning that most code that ran during the 2000s, can still be run with minimal change.

[1]: https://262.ecma-international.org/

[2]: https://www.w3.org/TR/

mrweasel · 1d ago
Dates in JavaScript is just a special kind of broken. Even with the more modern APIs for formatting dates it's just wonky at best.
thrdbndndn · 1d ago
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 "breaking change", 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.

By that, I don't mean to dismiss the importance of backward compatibility, but this case is particularly funny because:

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;

2. Having it behave differently from other "legacy forms," like the slash-separated version, is itself arguably a break in backward compatibility;

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 "breaking change" really was, considering you already had to write shim code either way.

nordiknomad5 · 1d ago
I am not sure why my brave browser does not console out the error as in the OP

console.log(new Date('2025/05/28').toDateString());

console.log(new Date('2025-05-28').toDateString());

console.log(new Date('2025-5-28').toDateString());

OutPut Below

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

dust42 · 1d ago
If your local timezone is GMT>=0, then you wont see it. A special form of a Heisenbug that you only see easily when located in the Americas, while when in Europe/Africa/Asia it is invisible unless you switch your local time zone to any GMT-X value.
nordiknomad5 · 23h ago
ok thanks for the clarification :)
fimdomeio · 22h ago
On a broader note for the ones out there not familiar with this "timeless" classic:

Falsehoods programmers believe about time gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b923ca

vladde · 1d ago
In Sweden, we can write dates as 28/5-25
0points · 1d ago
As another swede, I dare you!

We swedes use standardized ISO 8601 dates such as YYYY-MM-DD as dictated by our excellent government and you find it in use in our social security number, government correspondence and mostly everywhere.

rf15 · 1d ago
> YYYY-MM-DD as dictated by our excellent government

Same here in germany! ...Which is the reason why everyone ignores it in favour of the traditional format.

I love democracy, and also mountain-shaped temporal unit ordering ^ It's 28.05.2025 13:15.

Text-ordering by date is a nightmare because everything is first grouped by day-of-month, then month, then year! :)

dylan604 · 22h ago
So dates have endianness?
IAmBroom · 20h ago
And Americans use Middlianness. Middle-endianness?
dylan604 · 20h ago
great, now i've just wandered off wondering if there's psychology studies on the affect of one's endianness on their mental health. like, does one's parent object not show enough affection towards the middle-endian child objects vs their big-endian child objects, or will the little-endian child objects always win affection?
Philpax · 1d ago
Even more fun when that includes date or time ranges; I've literally had to paste Swedish-style dates into Claude to help me parse what the intended reading is.
hnbad · 1d ago
I guess some people just want to see the world burn.
Y_Y · 1d ago
-20.6
raverbashing · 1d ago
Being able to does not mean that you should
Scarblac · 1d ago
Not 28/5 '25?
lifthrasiir · 1d ago
Ah, usual issues with any old enough language with multiple popular implementations. Enjoy your standards. (At least ECMAScript is a relatively well-thought standard...)
pif · 1d ago
I'm missing the usual suspects complaining about how browsers exploit undefined behaviour and break programmers' expectations.
alex-knyaz · 1d ago
What are best practices/tips on handling date and time everyone has in general? Every time it is a bit of a nightmare.
c17r · 23h ago
Best I've seen is from the venerable Jon Skeet: https://codeblog.jonskeet.uk/2019/03/27/storing-utc-is-not-a...
happytoexplain · 23h ago
The best advice is unfortunately to not use a generalized practice. E.g. never "just use UTC". Use UTC when it makes sense.

- Understand the semantic difference between a timestamp (absolute time) and clock/calendar time (relative time). Understand which one your use case uses. Don't use one to store the other.

- If the use case calls for a relative time, do not manually construct or edit the date. Use your platforms date-creation/modification APIs, no matter how unnecessary they seem.

- Understand what is inside your platform's date types at rest. Understand which of your platform's date APIs pull in environmental information (time/tz/locale), as opposed to only using the arguments you pass it. Understand that your platform's 'print/stringify' function may be one of those aforementioned functions. Misunderstanding this often leads people to say inaccurate things. E.g. say your platform has a Date object that stores an epoch-based timestamp. People may say "the Date object is always in UTC", when really the Date object has no time offset, which is not the same thing.

- Understand that if you pass a date around platforms, it might accidentally be reserialized into the same absolute time, but a different relative time.

- Understand that there is a hierarchy of use cases, where each one has more complex requirements:

1. "Create/modify" timestamps; egg timers. (absolute time)

2. Alarm clocks (same clock time always).

3. One-time calendar events (has an explicit, static tz; same clock time if the user changes its day or time zone; different clock time if the user's time offset changes)

4. Recurring calendar events (same as above, except don't change the clock time if the user's time offset changed due to DST, as opposed to a geographic change)

5. Recurring calendar event with multiple participants (same as above, just remember that the attached tz is based on the creator, so the clock time will shift during DST for participants in a place without matching DST rules).

Note that a lot of platforms nowadays have built-in or 3rd party packages that automatically handle a lot of the rules in the above use cases.

Finally, understand that all those little weird things about dates (weird time zones, weird formatting conventions, legislative time zone changes, retroactive legislative time zone changes, leap days, leap seconds, times that don't exist), are good to know, but they will mostly be accounted for by the above understandings. You can get into them when you want to handle the real edge cases.

divan · 1d ago
hnbad · 1d ago
It's a good talk but it's an even better talk if you actually like JS and understand not only why those things are the way they are but also that you wouldn't ever do them in normal code.
poincaredisk · 21h ago
You wouldn't do them intentionally, but they're there waiting to bite you in the foot.
divan · 1d ago
Heartbreaking to hear that there are people who "actually like JS".
stevoski · 23h ago
I find it fascinating that JavaScript has so many "WTF?" things like this, and yet is so incredibly successful.

Being available everywhere (as far as browsers are concerned) trumps almost all other factors.

dotancohen · 23h ago
Photographers have a saying: The best camera in the world, is the camera you have on you.
Havoc · 1d ago
No idea but it makes perfect sense that the question is about JavaScript
Lev1a · 1d ago
glkindlmann · 1d ago
This was an informative (for me) explainer for what's happening in that video https://medium.com/dailyjs/the-why-behind-the-wat-an-explana...
HenryBemis · 22h ago
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.

[0]: https://xkcd.com/1179/

animanoir · 1d ago
I wish we could move on from this trash already.
TZubiri · 1d ago
we need to kill javascript with fire, or at least stop it from spreading
LandR · 1d ago
Javascript delenda est!
antisol · 22h ago
yep!

Just imagine building websites using literally any other language.

Sounds glorious, doesn't it?

whatevaa · 5h ago
Yup, brainfuck would be much better.
fatata123 · 22h ago
Like genital herpes, I am stuck with it. I might as well learn to like it. And eventually convert others across to the cause.
pif · 1d ago
Undocumented Undefined Behaviour, anyone?
hnbad · 1d ago
It's documented undefined behavior, really. Implementations are allowed to accept other input than ISO strings and interpret them how they like.

The real "bug" in the example is 2025/05/28 being May 28th because the implementation ignores timezones for that format.

The issue with `Date` is that it is based on the original `java.util.Date` class and inherits all of its problems: https://docs.oracle.com/en/java/javase/21/docs/api/java.base... - this is also where the wonky zero-indexed month value comes from. Note that Java deprecated all versions of the constructor other than the one taking a millisecond value or nothing, which JS can't do for backwards compatibility reasons.

Hopefully `Temporal` will solve these problems but how long that spec has been in the works should tell you how difficult this is to get right when anything you put on the web is forever.

meekaaku · 1d ago
how about postgres style timestamp and timestamptz

unless a timezone/offset is given, its considered plain date/time, not an epoch.