Temporal API
Dates in JavaScript are terrible. We all know this, but they’ve made big strides to prevent it from sucking anymore. So what do we get? No more weird constructor passing numbers around. Like you want now? Temporal.Now—it returns a proper prototypal object, not nonsense... and then everything gets easier.
I’m not going to explain these—you’ll just know how they work from reading. It’s that nice:
Temporal.Now.plainDateISO()
or how about:
Temporal.Now.add({days: 1})
or even:
Temporal.Now.add({days: 1}).subtract({years: 2})
Resources
- Great blog post which goes into way more detail
- Can I Use for your browser checks
- Deno supports it as of yesterday (of course, they’re amazing)
- No word on Node.js, but you could polyfill