Live data from Hacker News

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

brandondong.github.io

91–100 of 167 posts

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

#91
post #33

Earlier quoted context omitted.

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.

> even Microsoft gave up Ah yes, Microsoft, the defenders of the free world.

[deleted]

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

#92
post #57

Earlier quoted context omitted.

> 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…

> 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.

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.

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

#93
post #12
post #7

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…

Pro tip: never ever use anything but ISO dates in UTC tz unless you're displaying it for a user in a UI.

And if you need a date, then represent it as a date and not as a time point.

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

#94
post #12

Earlier quoted context omitted.

Pro tip: never ever use anything but ISO dates in UTC tz unless you're displaying it for a user in a UI.

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.

Yes, but whose timezone? The machine? The user? What about a machine to machine transaction?

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

#95
post #31

Earlier quoted context omitted.

Proer tip: never use anything but unix timestamp until presentation.

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.

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

#96
post #31

Earlier quoted context omitted.

Proer tip: never use anything but unix timestamp until presentation.

This is great until someone asks whether a particular event happened before or after lunch.

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.

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

#97
post #12

Earlier quoted context omitted.

Pro tip: never ever use anything but ISO dates in UTC tz unless you're displaying it for a user in a UI.

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?

#98

What are best practices/tips on handling date and time everyone has in general? Every time it is a bit of a nightmare.

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.

Post reply on HN