javascript class
Temporal.PlainTime
The Temporal.PlainTime object represents a time without a date or time zone; for example, a recurring event that happens at the same time every day. It is fundamentally represented as a combination of hour, minute, second, millisecond, microsecond, and nanosecond values.
Description
A PlainTime is essentially the time part of a PlainDateTime object, with the date information removed. Because the date and time information don’t have much interaction, all general information about time properties is documented here.
RFC 9557 format
PlainTime objects can be serialized and parsed using the RFC 9557 format, an extension to the ISO 8601 / RFC 3339 format. The string has the following form:
HH:mm:ss.sssssssss
HH- : A two-digit number from
00to23. It may be prefixed by the time designatorTort.
- : A two-digit number from
mmOptional- : A two-digit number from
00to59. Defaults to00.
- : A two-digit number from
ss.sssssssssOptional- : A two-digit number from
00to59. May optionally be followed by a.or,and one to nine digits. Defaults to00. TheHH,mm, andsscomponents can be separated by:or nothing. You can omit either justssor bothssandmm, so the time can be one of three forms:HH,HH:mm, orHH:mm:ss.sssssssss.
- : A two-digit number from
As an input, you may optionally include the date, offset, time zone identifier, and calendar, in the same format as PlainDateTime, but they will be ignored. A date-only string will be rejected. Other annotations in the [key=value] format are also ignored, and they must not have the critical flag.
When serializing, you can configure the fractional second digits.
Constructor
Temporal.PlainTime()- : Creates a new
Temporal.PlainTimeobject by directly supplying the underlying data.
- : Creates a new
Static methods
Temporal.PlainTime.compare()- : Returns a number (-1, 0, or 1) indicating whether the first time comes before, is the same as, or comes after the second time. Equivalent to comparing the hour, minute, second, millisecond, microsecond, and nanosecond fields one by one.
Temporal.PlainTime.from()- : Creates a new
Temporal.PlainTimeobject from anotherTemporal.PlainTimeobject, an object with time properties, or an RFC 9557 string.
- : Creates a new
Instance properties
These properties are defined on Temporal.PlainTime.prototype and shared by all Temporal.PlainTime instances.
Temporal.PlainTime.prototype.constructor- : The constructor function that created the instance object. For
Temporal.PlainTimeinstances, the initial value is theTemporal.PlainTime()constructor.
- : The constructor function that created the instance object. For
Temporal.PlainTime.prototype.hour- : Returns an integer from 0 to 23 representing the hour component of this time.
Temporal.PlainTime.prototype.microsecond- : Returns an integer from 0 to 999 representing the microsecond (10-6 second) component of this time.
Temporal.PlainTime.prototype.millisecond- : Returns an integer from 0 to 999 representing the millisecond (10-3 second) component of this time.
Temporal.PlainTime.prototype.minute- : Returns an integer from 0 to 59 representing the minute component of this time.
Temporal.PlainTime.prototype.nanosecond- : Returns an integer from 0 to 999 representing the nanosecond (10-9 second) component of this time.
Temporal.PlainTime.prototype.second- : Returns an integer from 0 to 59 representing the second component of this time.
Temporal.PlainTime.prototype[Symbol.toStringTag]- : The initial value of the
[Symbol.toStringTag]property is the string"Temporal.PlainTime". This property is used intoString().
- : The initial value of the
Instance methods
Temporal.PlainTime.prototype.add()- : Returns a new
Temporal.PlainTimeobject representing this time moved forward by a given duration (in a form convertible byTemporal.Duration.from()), wrapping around the clock if necessary.
- : Returns a new
Temporal.PlainTime.prototype.equals()- : Returns
trueif this time is equivalent in value to another time (in a form convertible byTemporal.PlainTime.from()), andfalseotherwise. They are compared by their time values. Equivalent toTemporal.PlainTime.compare(this, other) === 0.
- : Returns
Temporal.PlainTime.prototype.round()- : Returns a new
Temporal.PlainTimeobject representing this time rounded to the given unit.
- : Returns a new
Temporal.PlainTime.prototype.since()- : Returns a new
Durationobject representing the duration from another time (in a form convertible byTemporal.PlainTime.from()) to this time. The duration is positive if the other time is before this time, and negative if after.
- : Returns a new
Temporal.PlainTime.prototype.subtract()- : Returns a new
Temporal.PlainTimeobject representing this time moved backward by a given duration (in a form convertible byTemporal.Duration.from()), wrapping around the clock if necessary.
- : Returns a new
Temporal.PlainTime.prototype.toJSON()- : Returns a string representing this time in the same RFC 9557 format as calling
toString(). Intended to be implicitly called bystringify().
- : Returns a string representing this time in the same RFC 9557 format as calling
Temporal.PlainTime.prototype.toLocaleString()- : Returns a string with a language-sensitive representation of this time.
Temporal.PlainTime.prototype.toString()- : Returns a string representing this time in the RFC 9557 format.
Temporal.PlainTime.prototype.until()- : Returns a new
Durationobject representing the duration from this time to another time (in a form convertible byTemporal.PlainTime.from()). The duration is positive if the other time is after this time, and negative if before.
- : Returns a new
Temporal.PlainTime.prototype.valueOf()- : Throws a
TypeError, which preventsTemporal.PlainTimeinstances from being implicitly converted to primitives when used in arithmetic or comparison operations.
- : Throws a
Temporal.PlainTime.prototype.with()- : Returns a new
Temporal.PlainTimeobject representing this time with some fields replaced by new values.
- : Returns a new