A practical migration guide from Moment.js to the new JavaScript Temporal API, which reached TC39 Stage 4 and is already shipping in Chrome 144+ and Firefox 139+. Covers key differences including immutability (Temporal objects never mutate), 1-based month indexing, built-in time zone support without extra packages, and strict ISO 8601 parsing. Provides side-by-side code recipes for creating date/time objects, parsing, formatting via Intl.DateTimeFormat, date arithmetic, comparisons, and time zone conversions. Includes a real-world refactoring example of an event scheduling function. Also notes a polyfill (@js-temporal/polyfill) is available for Safari and older browsers, though it's still in alpha.

20m read timeFrom smashingmagazine.com
Post cover image
Table of contents
The Rise And Fall Of Moment.jsWhat Is Temporal?Creating Date And Time ObjectsParsingFormattingDate calculationsComparing Dates And TimesTime Zone ConversionsA Real-world RefactoringSummaryNotes On The Polyfill

Sort: