bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/JavaScript/Objects, Classes, and Advanced Patterns
JavaScript•Objects, Classes, and Advanced Patterns

JavaScript Temporal Conversion

Temporal Conversion Rules

The table below shows how Temporal types can be converted.

FromPlain DatePlain TimePlain DateTimeZoned DateTimeInstant
PlainDateNoYesNoNo
PlainTimeNoNoNoNo
PlainDateTimeYesYesYesNo
ZonedDateTimeYesYesYesYes
InstantNoNoNoYes

Conversion Methods

FromToMethod
DateInstantdate .toTemporalInstant()
PlainDatePlainTimeNone
PlainDatePlainDateTimedate .toPlainDateTime()
PlainDateZonedTimeNone
PlainDateInstantNone
PlainYearMonthPlainDateyearmonth .toPlainDate()
PlainMonthDayPlainDatemonthday .toPlainDate()
PlainDateTimePlainDatedatetime .toPlainDate()
PlainDateTimePlainTimedatetime .toPlainTime()
PlainDateTimeZonedDateTimedatetime .toZonedDateTime()
PlainDateTimeInstantNone
ZonedDateTimePlainDatezoned .toPlainDate()
ZonedDateTimePlainDateTimezoned .toPlainDateTime()
ZonedDateTimePlainTimezoned .toPlainTime()
ZonedDateTimeInstantzoned .toInstant()
InstantZonedDateTimezoned .toZonedDateTimeISO()

Legacy Date to Temporal Instant

Example

const legacyDate = new Date();
const instant = legacyDate.toTemporalInstant();

PlainDate to PlainDateTime

You might like to add a time.

Examples

const date = Temporal.PlainDate.from("2026-05-17");
const dateTime = date.toPlainDateTime();

Combine Date and Time

You can combine PlainDate and PlainTime to create a PlainDateTime object.

Example

// Create a PlainDate object
const date = Temporal.PlainDate.from("2026-05-17");
// Create a PlainTime object
const time = Temporal.PlainTime.from("14:30");
// Convert into a PlainDateTime object
const dateTime = date.toPlainDateTime(time);

PlainDateTime to PlainDate

Example

const dateTime = Temporal.PlainDateTime.from("2026-05-17T14:30");
const date = dateTime.toPlainDate();

PlainDateTime to PlainTime

Example

const dateTime = Temporal.PlainDateTime.from("2026-05-17T14:30");
const time = dateTime.toPlainTime();

PlainDateTime to ZonedDateTime

PlainDateTime does not contain a time zone.

You must provide one to create a ZonedDateTime.

Wrong

const dateTime = Temporal.PlainDateTime.from("2026-05-17T14:30");
const zoned = dateTime.toZonedDateTime();

ZonedDateTime to PlainDateTime

Example

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

ZonedDateTime to PlainDate

Example

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

ZonedDateTime to PlainTime

Example

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

ZonedDateTime to Instant

Example

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

Instant to ZonedDateTime

Instant does not have a toZonedDateTime() method.

You must convert it to a ISO zone first.

Wrong

const instant = Temporal.Instant.from("2026-05-17T12:30:00Z");
const zoned = instant.toZonedDateTime("Europe/Oslo");

Special Temporal Types

FromtoPlainDate()toPlainDateTime()toZonedDateTime()
PlainYearMonthYES + day valueNoNo
PlainMonthDayYES + year valueNoNo

PlainMonthDay and PlainYearMonth need missing parts before becoming a full date.

PlainYearMonth to PlainDate

Example

const yearMonth = new Temporal.PlainYearMonth(2026, 5);
const date = yearMonth.toPlainDate({ day: 17 });

PlainMonthDay to PlainDate

Example

const monthDay = new Temporal.PlainYearMonth(2026, 5);
const date = monthDay.toPlainDate({ year: 2026 });

Time Zone Conversion

Converting time from another time zone is handled by the ZonedDateTime method withTimeZone().

Example

const zdtOslo = Temporal.Now.zonedDateTimeISO('Europe/Oslo');
const zdtTokyo = zdtOslo.withTimeZone('Asia/Tokyo');

Previous

JavaScript Object Management

Next

JavaScript Object Protection