Migrating from Moment.js to the JS Temporal API
JavaScript has evolved significantly in handling time, from the built-in Date API to Moment.js and now the Temporal API. The new standard fills gaps in the original Date API while addressing limitations found in Moment and other libraries.
The Rise and Fall of Moment.js
Moment.js is a JavaScript library with powerful utilities for working with times and dates. It includes missing features from the basic Date API, such as time zone manipulation, and makes many common operations simpler. However, Moment also had its share of issues, including a large library size and mutable objects.
Meet Temporal
Temporal is a new time and date API being added to the ECMAScript standard. As of March 2026, it has reached Stage 4 of the TC39 process and will be included in the next version of the ECMAScript specification. It has already been implemented in several browsers, including Chrome 144+ and Firefox 139+, with Safari expected to follow soon.
Key Features of Temporal
- Times with or without dates
- Time zone support
- Immutability
- 1-based indexing
Creating Date and Time Objects
To create a Moment object representing the current date and time, use the moment function. However, Moment objects are mutable and can cause unexpected behavior in situations like Daylight Saving Time or leap years.
const now = moment();
console.log(now);
// Moment<2026-02-18T21:26:29-05:00>
Temporal is more flexible and can create objects representing the current date and time by creating a Temporal.Instant object. This represents a point in time defined by the time since “the epoch” (midnight UTC on January 1, 1970).
const now = Temporal.Now.instant();
// see raw nanoseconds since the epoch
console.log(now.epochNanoseconds);
// 1771466342612000000n
// format for UTC
console.log(now.toString());
// 2026-02-19T01:55:27.844Z
Migrating from Moment to Temporal
The rest of this article will look at some “recipes” for migrating Moment-based code to the new Temporal API. Let’s start refactoring!
Creating Date and Time Objects
To create a Temporal object representing the current date and time, use the Temporal.Now.instant() method.
const now = Temporal.Now.instant();
// see raw nanoseconds since the epoch
console.log(now.epochNanoseconds);
// 1771466342612000000n
// format for UTC
console.log(now.toString());
// 2026-02-19T01:55:27.844Z
You can also create other types of Temporal objects, including Temporal.PlainDate, Temporal.PlainTime, and Temporal.ZonedDateTime.
Conclusion
Migrating from Moment.js to the JS Temporal API can be a complex task, but with the right guidance, it can be done efficiently. By understanding the key features of Temporal and how to create date and time objects, you can start refactoring your code and take advantage of the new standard.
Remember to test your code thoroughly and address any issues that may arise during the migration process. With the right approach, you can ensure a smooth transition to the Temporal API and take your JavaScript development to the next level.







