Loading lesson path
Temporal.PlainTime object is a time object without a date.
Formula
It represents an ISO 8601 wall - clock time without a date or time zone.10:30:00.
Formula
It is useful for opening hours, alarms, and any time - only values.The Temporal.PlainTime Object
Temporal PlainTime object is a time object with no date.
Formula
It represents an ISO 8601 wall - clock time without a date or time zone.14:30:00.
const date = new Temporal.PlainTime(14, 30);You can create a PlainTime from a string.
const time = Temporal.PlainTime.from("14:30");You can also create a PlainTime using numeric values.
const time = new Temporal.PlainTime(14, 30);The parameters are: hour, minute, second, millisecond, microsecond, nanosecond.
You can get the current local time using Temporal.Now.plainTimeISO().
const now = Temporal.Now.plainTimeISO();You can read the different parts of a PlainTime value.
const time = Temporal.PlainTime.from("14:30:15.123");and subtract() to do time math. PlainTime is immutable, so the original value is not changed.
const time = Temporal.PlainTime.from("14:30");
const later = time.add({ minutes: 45 });
const earlier = time.subtract({ hours: 2 });If the time passes midnight, it wraps around:
const time = Temporal.PlainTime.from("23:30");
const result = time.add({ minutes: 90 });method calculates the duration between two temporal dates. Syntax t1.since( t2, options )
At time t1, how much time has passed since time t2 ?
const start = Temporal.PlainTime.from("09:00");
const end = Temporal.PlainTime.from("17:30");
const duration = end.since(start);method returns a Temporal.Duration Object representing the elapsed time. The duration is positive if the "other" date is in the past. The duration is negative if the "other" date is in the future.
Temporal.PlainTime.compare() to compare times.