JavaScript Temporal Now
Temporal is the modern way to work with dates and times in JavaScript.
The Temporal.Now object provides clear and flexible ways to get the current date and time.
The Temporal.Now object has methods for getting the current time in various formats.
Unlike the JavaScript Date object, Temporal lets you choose exactly what type of value you want.
See examples of Instant, PlainDate, and ZonedDateTime.
Temporal.Now
Use the Temporal.Now.zonedDateTimeISO() method for current system time:
Use the Temporal.Now.plainDateISO() method for calender date only:
Get the Current Instant
An Instant represents an exact moment in time (UTC).
It is similar to a timestamp.
This returns the current moment in UTC.
Get the Current Date (ISO)
If you only need today's date (year, month, day), use plainDateISO().
This returns a PlainDate object using the ISO calendar.
Get the Current Date and Time (No Time Zone)
Use plainDateTimeISO() to get the current date and time without a time zone.
This is useful when you need local date and time but not time zone calculations.
Get the Current Date and Time with Time Zone
Use zonedDateTimeISO() when you need time zone information.
This returns a ZonedDateTime that includes your system's time zone.
Compare With Date
With Date, you only get one type of object.
Temporal gives you separate types depending on what you need.
Instant- Exact moment in UTC.PlainDate- Date only.PlainDateTime- Date and time without zone.ZonedDateTime- Date and time with zone.
When to Use Each Method
Use
instant()for timestamps and comparisons.Use
plainDateISO()for birthdays and calendar dates.Use
plainDateTimeISO()for local scheduling.Use
zonedDateTimeISO()for international or time zone-aware applications.