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 TOOLS

Basic JavaScript

JS Tutorial JS Introduction JS Where To JS Output

JS Syntax

JS Syntax JS Statements JS Comments JS Variables JS Let JS Const JS Types

JS Operators

JS Operators JS Arithmetic JS Assignment JS Comparisons JS Conditional JS If JS If Else JS Ternary JS Switch JS Booleans JS Logical

JS Loops

JS Loops JS Loop for JS Loop while JS Break JS Continue JS Control Flow

JS Strings

JS Strings JS String Templates JS String Methods JS String Search JS String Reference

JS Numbers

JS Numbers JS Number Methods JS Number Properties JS Number Reference JS Bitwise JS BigInt

JS Functions

Function Path Function Intro Function Invocation Function Parameters Function Returns Function Arguments Function Expressions Function Arrow Function Quiz

JS Objects

Object Path Object Intro Object Properties Object Methods Object this Object Display Object Constructors

JS Scope

JS Scope JS Code Blocks JS Hoisting JS Strict Mode

JS Dates

JS Dates JS Date Formats JS Date Get JS Date Set JS Date Methods

JS Arrays

JS Arrays JS Array Methods JS Array Search JS Array Sort JS Array Iterations JS Array Reference JS Array Const

JS Sets

JS Sets JS Set Methods JS Set Logic JS Set WeakSet JS Set Reference

JS Maps

JS Maps JS Map Methods JS Map WeakMap JS Map Reference

JS Iterations

JS Loops JS Iterables JS Iterators JS Generators

JS Math

JS Math JS Math Reference JS Math Random

JS RexExp

JS RegExp JS RegExp Flags JS RegExp Classes JS RegExp Metachars JS RegExp Assertions JS RegExp Quantifiers JS RegExp Patterns JS RegExp Objects JS RegExp Methods

JS Data Types

JS Destructuring JS Data Types JS Primitive Data JS Object Types JS typeof JS toString JS Type Conversion

JS Errors

JS Errors Intro JS Errors Silent JS Error Statements JS Error Object

JS Debugging

Debugging Intro Debugging Console Debugging Breakpoints Debugging Errors Debugging Async Debugging Reference

JS Conventions

JS Style Guide JS Best Practices JS Mistakes JS Performance

JS References

JS Statements JS Reserved Keywords JS Operators JS Precedence

JS Versions

JS 2026 JS 2025 JS 2024 JS 2023 JS 2022 JS 2021 JS 2020 JS 2019 JS 2018 JS 2017 JS 2016 JS Versions JS 2015 (ES6) JS 2009 (ES5) JS 1999 (ES3) JS IE / Edge JS History

JS HTML

JS HTML DOM JS Events JS Projects New

JS Advanced

JS Temporal  New 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 Format Temporal Dates

Convert Dates to Strings

Temporal values can be converted to strings in different ways.

Temporal values can be formatted as:

  • RFC 9557 (toString)
  • Local strings (toLocaleString)
  • Fully customized strings (Intl.DateTimeFormat)

The ISO 8601 Standard

ISO 8601

ISO 8601 is the international standard for representing dates and times..

It is a machine-readable format (YYYY-MM-DD) designed to eliminate confusion caused by regional date variations.

It follows a "largest to smallest" hierarchy (year, month, day, hour, minute, second) which ensures that dates are alphabetically sortable.

Note

ISO 8601 avoids confusion between regional formats like

  • MM/DD/YYYY (US format)
  • DD/MM/YYYY (European format)

ISO 8601 Strings

An ISO 8601 string represents dates and times in a structured and sortable format:.

A 4-digit year, 2-digit month, 2-digit day and a 'T' separator for time, often in UTC time (ending with 'Z' for Zulu):

FormatFormatExample
Date (4-digit year)YYYY-MM-DD2026-05-17
Time (24 hour clock)hh:mm:ss 14:30:00
Date & Time UTCYYYY-MM-DDThh:mm:ssZ2026-05-17T14:30:00Z
Date & Time OffsetYYYY-MM-DDThh:mm:ss±hh:mm2026-05-17T14:30:00+01:00
Week DateYYYY-Www-D2026-W20-7
Ordinal Date (001-366)YYYY-nnn2026-074
Duration formatPnYnMnDTnHnMnSP3Y6M4DT12H30M5S

The RF 3339 Format

RFC 3339 is the Internet standard for Date and Time Formats.

It is used to represent timestamps in a way that is consistent across different computer systems.

  • Format
    It follows the pattern YYYY-MM-DDThh:mm:ssZ.
    2026-05-17T14:30:00Z represents May 17, 2026, at 2:30 PM UTC.
  • Relation to ISO 8601
    It is a subset of the ISO 8601 standard, designed specifically for use in Internet protocols.
  • Time Zones
    It requires an time zone, either as "Z" for UTC (Zulu time) or as an offset (e.g. -05:00).
  • Flexibility Unlike ISO 8601, RFC 3339 allows the "T" separator between the date and time to be replaced by a space for better readability.
  • Web APIs
    It is the default format for timestamps in JSON and RESTful APIs.
  • Programming
    Most modern languages have built-in support for this format, such as toISOString() in JavaScript

The RFC 9557 Format

RFC 9557 is the primary string format used by JavaScript Temporal date objects to represent zoned date-times and plain dates.

It was created because ISO 8601 and RFC 3339 timestamps only provide UTC offsets (like -05:00), which does not contain enough information to determine the actual geographical time zone or handle future DST (Daylight Saving Time) changes.

RFC 9557 is not strictly a part of the ISO 8601 standard. Instead, it is an extension to RFC 3339, which itself is a simplified "profile" of ISO 8601 designed for internet use.

While these standards are closely related, here is how the relationship works:

  • ISO 8601
    The international standard for date and time representation.
  • RFC 3339:
    A subset of ISO 8601 specifically for the Internet.
  • RFC 9557
    An extension to RFC 3339 with new features like time zone names ([Europe/Oslo]) and calendar names ([u-ca=hebrew]).
FeatureISO 8601RFC 3339RFC 9557
FormatYYYY-MM-DDTHH:MM:SSZSameSame
UTC OffsetYesYesYes
IANA ZoneNoNo[America/New_York]
CalendarISO onlyISO only[u-ca=hebrew]
CompabileThe StandardSubset of ISO 8601Extends 3339

Format with toString()

The toString() method returns a standard ISO string.

Example

const date = Temporal.PlainDate.from("2026-02-17");

let text = date.toString();

Result:

2026-02-17

Format PlainTime

A PlainTime value is formatted as a time string.

Example

const time = Temporal.PlainTime.from("14:30:15");

let text = time.toString();

Result:

14:30:15

Format PlainDateTime

A PlainDateTime value includes both date and time.

Example

const dateTime = Temporal.PlainDateTime.from("2026-02-17T14:30:15");

let text = dateTime.toString();

Result:

2026-02-17T14:30:15

Format ZonedDateTime

A ZonedDateTime string includes the offset and time zone.

Example

const zoned = Temporal.ZonedDateTime.from(
"2026-02-17T14:30:15+01:00[Europe/Oslo]");
let text = zoned.toString();

Result:

2026-02-17T14:30:15+01:00[Europe/Oslo]

Remove Smaller Time Units

You can control how much detail to include.

For example, you can hide seconds or milliseconds.

Example

const time = Temporal.PlainTime.from("14:30:15.123");

let text = time.toString({ smallestUnit: "minute" });

Result:

14:30

Control Fractional Digits

You can choose how many decimal digits to include.

Example

const time = Temporal.PlainTime.from("14:30:15.123456789");

let text = time.toString({ fractionalSecondDigits: 3 });

Result:

14:30:15.123

Format with toLocaleString()

Use toLocaleString() to format a value using the user's locale.

Example

const date = Temporal.PlainDate.from("2026-02-17");

console.log(date.toLocaleString("en-US"));
console.log(date.toLocaleString("de-DE"));

The output depends on the chosen locale.


Format with Intl.DateTimeFormat

Use Intl.DateTimeFormat when you need more control over the output.

Example

const date = Temporal.PlainDate.from("2026-02-17");

const formatter = new Intl.DateTimeFormat("en-US", {
  year: "numeric",
  month: "long",
  day: "numeric"
});

let text = formatter.format(date);

Result:

February 17, 2026

Format Date and Time Together

You can format a PlainDateTime with both date and time options.

Example

const dateTime = Temporal.PlainDateTime.from("2026-02-17T14:30:15");

const formatter = new Intl.DateTimeFormat("en-GB", {
  year: "numeric",
  month: "short",
  day: "numeric",
  hour: "2-digit",
  minute: "2-digit"
});

let text = formatter.format(dateTime);

Format ZonedDateTime in a Locale

When formatting a ZonedDateTime, the time zone is included in the calculation.

Example

const zoned = Temporal.ZonedDateTime.from(
"2026-02-17T14:30:15+01:00[Europe/Oslo]");

const formatter = new Intl.DateTimeFormat("en-US", {
  dateStyle: "full",
  timeStyle: "short"
});

let text = formatter.format(zoned);

When to Use Each Method

  • Use toString() for standard ISO output.

  • Use toLocaleString() for simple local formatting.

  • Use Intl.DateTimeFormat for custom formatting.


×

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.

-->