How did they manage to build the entire modern Web on a language without a standard library?
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 b…
Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
101–110 of 167 posts
Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
#102Hang 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…
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.
Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
#103Hang 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…
Pro tip: never ever use anything but ISO dates in UTC tz unless you're displaying it for a user in a UI.
> 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.Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
#104Earlier quoted context omitted.
There's no reliable way to map it back into the local time in the past, unless you also safe the UTC offset.
If you record them with some known UTC offset regardless of localtime (e.g. 0), you can convert to local time in the past.
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".
Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
#105Earlier quoted context omitted.
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.
Why not store it as a time date in the original timezone then?
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.
Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
#106Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
#107How did they manage to build the entire modern Web on a language without a standard library?
Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
#108I 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
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.
Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
#109Earlier quoted context omitted.
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…
All solutions have problems, but I think UTC midnight is simpler than dealing with mixed date formats in the backend.
Re: Why are 2025/05/28 and 2025-05-28 different days in JavaScript?
#110Earlier quoted context omitted.
> That is not a better world. Not a better world, just the current world.
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.