Temporal.PlainTime
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
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 Temporal.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
00
to23
. It may be prefixed by the time designatorT
ort
. mm
Optional-
A two-digit number from
00
to59
. Defaults to00
. ss.sssssssss
Optional-
A two-digit number from
00
to59
. May optionally be followed by a.
or,
and one to nine digits. Defaults to00
. TheHH
,mm
, andss
components can be separated by:
or nothing. You can omit either justss
or bothss
andmm
, so the time can be one of three forms:HH
,HH:mm
, orHH:mm:ss.sssssssss
.
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()
Experimental-
Creates a new
Temporal.PlainTime
object by directly supplying the underlying data.
Static methods
Temporal.PlainTime.compare()
Experimental-
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()
Experimental-
Creates a new
Temporal.PlainTime
object from anotherTemporal.PlainTime
object, an object with time properties, or an RFC 9557 string.
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.PlainTime
instances, the initial value is theTemporal.PlainTime()
constructor. Temporal.PlainTime.prototype.hour
Experimental-
Returns a integer from 0 to 23 representing the hour component of this time.
Temporal.PlainTime.prototype.microsecond
Experimental-
Returns a integer from 0 to 999 representing the microsecond (10-6 second) component of this time.
Temporal.PlainTime.prototype.millisecond
Experimental-
Returns a integer from 0 to 999 representing the millisecond (10-3 second) component of this time.
Temporal.PlainTime.prototype.minute
Experimental-
Returns a integer from 0 to 59 representing the minute component of this time.
Temporal.PlainTime.prototype.nanosecond
Experimental-
Returns a integer from 0 to 999 representing the nanosecond (10-9 second) component of this time.
Temporal.PlainTime.prototype.second
Experimental-
Returns a 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 inObject.prototype.toString()
.
Instance methods
Temporal.PlainTime.prototype.add()
Experimental-
Returns a new
Temporal.PlainTime
object representing this time moved forward by a given duration (in a form convertible byTemporal.Duration.from()
), wrapping around the clock if necessary. Temporal.PlainTime.prototype.equals()
Experimental-
Returns
true
if this time is equivalent in value to another time (in a form convertible byTemporal.PlainTime.from()
), andfalse
otherwise. They are compared by their time values. Equivalent toTemporal.PlainTime.compare(this, other) === 0
. Temporal.PlainTime.prototype.round()
Experimental-
Returns a new
Temporal.PlainTime
object representing this time rounded to the given unit. Temporal.PlainTime.prototype.since()
Experimental-
Returns a new
Temporal.Duration
object 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. Temporal.PlainTime.prototype.subtract()
Experimental-
Returns a new
Temporal.PlainTime
object representing this time moved backward by a given duration (in a form convertible byTemporal.Duration.from()
), wrapping around the clock if necessary. Temporal.PlainTime.prototype.toJSON()
Experimental-
Returns a string representing this time in the same RFC 9557 format as calling
toString()
. Intended to be implicitly called byJSON.stringify()
. Temporal.PlainTime.prototype.toLocaleString()
Experimental-
Returns a string with a language-sensitive representation of this time.
Temporal.PlainTime.prototype.toString()
Experimental-
Returns a string representing this time in the RFC 9557 format.
Temporal.PlainTime.prototype.until()
Experimental-
Returns a new
Temporal.Duration
object 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. Temporal.PlainTime.prototype.valueOf()
Experimental-
Throws a
TypeError
, which preventsTemporal.PlainTime
instances from being implicitly converted to primitives when used in arithmetic or comparison operations. Temporal.PlainTime.prototype.with()
Experimental-
Returns a new
Temporal.PlainTime
object representing this time with some fields replaced by new values.
Specifications
Specification |
---|
Temporal proposal # sec-temporal-plaintime-objects |
Browser compatibility
BCD tables only load in the browser