3 ms·
The article is super weird. It never mentions Date.now(). It dances around the subject and exhaustively mentions the equivalent convention for Temporal. If y
by austin-cheney 10mo ago
The article is super weird. It never mentions Date.now(). It dances around the subject and exhaustively mentions the equivalent convention for Temporal.
If you want Date to act like Temporal then only use Date.now() as your starting point. It generates the number of milliseconds since 1 Jan 1970. That means the starting output is a number type in integer form. It does not represent a static value, but rather the distance between now and some universal point in the past, a relationship. Yes, Temporal is a more friendly API, but the primary design goal is to represent time as a relational factor.
Then you can format the Date.now() number it into whatever other format you want.
- ffsm8 10mo agothe article has examples of unexpected behavior with timestamps too, so... How do you covert to your desired format without going through Date? Please don't say date-fns
- austin-cheney 10mo agoI do not believe you understood the comment you replied to. A date number, whether from Date.now() or the Temporal equivalent, is not a time stamp value. It’s just a number.
- ffsm8 10mo agoThen I do not believe you understood the article you've commented on, because it essentially about the thing you handwaved away via > Then you can format the Date.now() number it into whatever other format you want. The while thing is about how to transition from a date, wherever it's string or timestamp to a date object. The idea is that you'll either format it to a string, do equality checks, calculate durations etc after after. Your idea of using timestamps doesn't address anything the article was about
- elendee 10mo agoI think the workflow your OP here and I use treats the timestamps (numbers) as the only value that matters. The "converted to" format is always just a temporary client side rendering, so the meticulous attention to conversions seems overkill. But I do see that there is tons of stuff about Date that is best ignored