Browse Source

Add post

Yarmo Mackenbach 1 week ago
1 changed files with 29 additions and 0 deletions
  1. +29

+ 29
- 0
content/notes/2020/09/ View File

@ -0,0 +1,29 @@
title: "The Post-MomentJS Era"
author: Yarmo Mackenbach
slug: post-momentjs-era
date: "2020-09-15 09:46:54"
published: true
## The Post-MomentJS Era
According to their [own documentation](, new projects should no longer use [MomentJS](, mentioning its hefty size and its outdated architecture as the principal reasons behind this statement.
Although there are new libraries that they do recommend, we also have a different solution nowadays: no library.
Using ECMAScript [Intl](, we can go a very long way formatting dates without dependencies.
`Intl.DateTimeFormat("en", { year: 'numeric', month: 'long', day: 'numeric', hour: "numeric", minute: "numeric", hour12: false, timeZone: 'CET' }).format(new Date()); // -> September 15, 2020, 09:41`
`Intl.DateTimeFormat(navigator.language, { year: 'numeric', month: 'long', day: 'numeric', hour: "numeric", minute: "numeric", hour12: false, timeZone: 'CET' }).format(new Date()); // -> 15 september 2020 09:41 <- In dutch!`
ISO formatting with `Intl` is tricky. But we don't need it.
`new Date().toISOString(); // --> 2020-09-15T07:41:41.148Z`
`new Date().toISOString().split("T")[0]; // -> 2020-09-15`
Have a look at the [MDN docs]( for more information.
Even though `Intl` and `Date` are viable options, the MomentJS developers recommend a few libraries to help with some browser inconsistencies. Make sure to [read the MomentJS post]( for all the pros and cons.