Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Scope JS Dates JS Temporal Dates JS Arrays JS Sets JS Maps JS Iterations JS Math JS RegExp JS Destructuring JS Data Types JS Errors JS Debugging JS Conventions JS References JS 2026 JS Versions

JS HTML

JS HTML DOM JS Events JS Projects New

JS Advanced

JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Windows JS Web APIs JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


JavaScript Temporal Instant

Working with Exact Time

A Temporal.Instant represents an exact moment in time.

It is similar to a timestamp and is always stored in UTC.

Learn how to use JavaScript Temporal.Instant to work with exact moments in time.

Compare Instants, convert from timestamps, and replace Date.now().

Note

Temporal is the modern way to work with dates and times in JavaScript.


Create an Instant

An Instant represents an exact moment in UTC time.

You can create an Instant from the current time:

Example

let now = Temporal.Now.instant();
Try it Yourself »

This returns the exact current moment in UTC.


Create an Instant from a String

You can also create an Instant from an ISO 8601 string.

Example

let instant = Temporal.Instant.from("2026-05-01T12:00:00Z");
Try it Yourself »

The Z at the end means UTC time.


Create an Instant from Epoch Milliseconds

You can create an Instant from a Unix timestamp (milliseconds since 1970-01-01).

Example

let instant = Temporal.Instant.fromEpochMilliseconds(1760721600000);
Try it Yourself »

This is similar to how Date works internally.


Replace Date.now()

With Date, you often use Date.now() to get the current timestamp.

Date Example

let timestamp = Date.now();
console.log(timestamp);

With Temporal, you can use:

Temporal Example

let instant = Temporal.Now.instant();
console.log(instant.epochMilliseconds);

The property epochMilliseconds returns the timestamp value.


Compare Instants

Instants can be compared directly.

Example

let a = Temporal.Instant.from("2026-02-17T12:00:00Z");
let b = Temporal.Instant.from("2026-02-18T12:00:00Z");

console.log(a < b);

This works because both values represent exact UTC moments.


Convert Instant to Date and Time

An Instant does not include time zone information.

You must convert it to a ZonedDateTime to display local time.

Example

let instant = Temporal.Now.instant();
let zoned = instant.toZonedDateTimeISO("Europe/Oslo");

console.log(zoned);

This converts the UTC moment to a specific time zone.


When to Use Instant

  • When storing timestamps in a database.

  • When comparing exact moments in time.

  • When working with logs or events.

  • When you need a UTC-based value.

Use Instant when you care about the exact moment, not how it looks in a time zone.


Summary

Temporal.Instant represents an exact UTC moment in time.

It replaces timestamp usage with Date and provides clearer and safer comparisons.



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->