Skip to main content

An Iso.Time represents a wall-clock time without any time zone. "Wall-clock time" refers to the concept of a time as expressed in everyday usage — the time that you read off the clock on the wall. For example, it could be used to represent an event that happens daily at a certain time, no matter what time zone.

Accessors and arithmetic operate at millisecond precision, but the string representation itself preserves whatever fractional-second precision was parsed (including sub-millisecond), matching the underlying Temporal behavior.

Iso.Time refers to a time with no associated calendar date; if you need to refer to a specific time on a specific day, use Iso.DateTime. A Iso.Time can be converted into a Iso.ZonedDateTime by combining it with a Iso.Date and Iso.TimeZone using the toZonedDateTime() function. It can also be combined with a Iso.Date to yield a "zoneless" Iso.DateTime using the toDateTime() function.

now()

now(timeZone?): Time

This method gets the current wall-clock time according to the system settings. Optionally a time zone can be given in which the time is computed, instead of the current system time zone.

Parameters

timeZone?

string

The time zone to get the current date and time in as a string. If not given, the current system time zone will be used.

Returns

Time

an Iso.Time string representing the current system time.


fromNumbers()

fromNumbers(hour?, minute?, second?, millisecond?): Time

Parameters

hour?

number

minute?

number

second?

number

millisecond?

number

Returns

Time


isValid()

isValid(time): time is Time

Parameters

time

unknown

Returns

time is Time


assertIsValid()

assertIsValid(time): asserts time is Time

Parameters

time

unknown

Returns

asserts time is Time


getHour()

getHour(time): number

Parameters

time

Time

Returns

number


getMinute()

getMinute(time): number

Parameters

time

Time

Returns

number


getSecond()

getSecond(time): number

Parameters

time

Time

Returns

number


getMillisecond()

getMillisecond(time): number

Parameters

time

Time

Returns

number


with()

with(time, timeLike, options?): Time

Parameters

time

Time

timeLike

hour?

number

minute?

number

second?

number

millisecond?

number

options?

overflow

"constrain" | "reject"

Returns

Time


add()

add(time, temporalDurationLike, options?): Time

Parameters

time

Time

temporalDurationLike

Duration | { years?: number; months?: number; weeks?: number; days?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }

options?

overflow?

"constrain" | "reject"

Returns

Time


subtract()

subtract(time, temporalDurationLike, options?): Time

Parameters

time

Time

temporalDurationLike

Duration | { years?: number; months?: number; weeks?: number; days?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }

options?

overflow?

"constrain" | "reject"

Returns

Time


until()

until(time, other, options?): Duration

Parameters

time

Time

other

Time

options?

largestUnit?

LargestUnit\<TimeUnit>

smallestUnit?

SmallestUnit\<TimeUnit>

roundingIncrement?

number

roundingMode?

RoundingMode

Returns

Duration


since()

since(time, other, options?): Duration

Parameters

time

Time

other

Time

options?

largestUnit?

LargestUnit\<TimeUnit>

smallestUnit?

SmallestUnit\<TimeUnit>

roundingIncrement?

number

roundingMode?

RoundingMode

Returns

Duration


round()

round(time, options): Time

Parameters

time

Time

options

smallestUnit

SmallestUnit\<TimeUnit>

roundingIncrement?

number

roundingMode?

RoundingMode

Returns

Time


equals()

equals(time, other): boolean

Parameters

time

Time

other

Time

Returns

boolean


isEqual()

isEqual(time, other): boolean

Parameters

time

Time

other

Time

Returns

boolean


toDateTime()

toDateTime(time, date): DateTime

Parameters

time

Time

date

Date

Returns

DateTime


toZonedDateTime()

toZonedDateTime(time, item): ZonedDateTime

Parameters

time

Time

item

date

Date

timeZone

string

Returns

ZonedDateTime


getFields()

getFields(time): TimeSlots

Parameters

time

Time

Returns

TimeSlots


from()

from(item, options?): Time

Parameters

item

string | Partial\<TimeSlots>

options?

overflow

"constrain" | "reject"

Returns

Time


compare()

compare(one, two): number

Parameters

one

Time

two

Time

Returns

number


format()

format(time, format, options?): string

Parameters

time

Time

the original date

format

string

the string of tokens

options?

FormatOptions

Returns

string

the formatted date string

Description

Return the formatted ZonedDateTime string in the given format.

The characters wrapped between two single quotes characters (') are escaped. Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote. (see the last example)

Format of the string is based on Unicode Technical Standard #35: https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table with a few additions (see note 7 below the table).

Accepted patterns:

UnitPatternResult examplesNotes
AM, PMa..aaAM, PM
aaaam, pm
aaaaa.m., p.m.1
aaaaaa, p
AM, PM, noon, midnightb..bbAM, PM, noon, midnight
bbbam, pm, noon, midnight
bbbba.m., p.m., noon, midnight1
bbbbba, p, n, mi
Flexible day periodB..BBBat night, in the morning, ...
BBBBat night, in the morning, ...1
BBBBBat night, in the morning, ...
Hour [1-12]h1, 2, ..., 11, 12
ho1st, 2nd, ..., 11th, 12th3
hh01, 02, ..., 11, 12
Hour [0-23]H0, 1, 2, ..., 23
Ho0th, 1st, 2nd, ..., 23rd3
HH00, 01, 02, ..., 23
Hour [0-11]K1, 2, ..., 11, 0
Ko1st, 2nd, ..., 11th, 0th3
KK01, 02, ..., 11, 00
Hour [1-24]k24, 1, 2, ..., 23
ko24th, 1st, 2nd, ..., 23rd3
kk24, 01, 02, ..., 23
Minutem0, 1, ..., 59
mo0th, 1st, ..., 59th3
mm00, 01, ..., 59
Seconds0, 1, ..., 59
so0th, 1st, ..., 59th3
ss00, 01, ..., 59
Fraction of secondS0, 1, ..., 9
SS00, 01, ..., 99
SSS000, 001, ..., 999
SSSS...2
Long localized timep12:00 AM3
pp12:00:00 AM3

Notes:

  1. Any sequence of the identical letters is a pattern, unless it is escaped by the single quote characters (see below). If the sequence is longer than listed in table (e.g. EEEEEEEEEEE) the output will be the same as default pattern for this unit, usually the longest one (in case of ISO weekdays, EEEE). Default patterns for units are marked with "2" in the last column of the table.

    format("2017-11-06", 'MMM') //=> 'Nov'

    format("2017-11-06", 'MMMM') //=> 'November'

    format("2017-11-06", 'MMMMM') //=> 'N'

    format("2017-11-06", 'MMMMMM') //=> 'November'

    format("2017-11-06", 'MMMMMMM') //=> 'November'

  2. Some patterns could be unlimited length (such as yyyyyyyy). The output will be padded with zeros to match the length of the pattern.

    format("2017-11-06", 'yyyyyyyy') //=> '00002017'

  3. These patterns are not in the Unicode Technical Standard #35:

    • o: ordinal number modifier
    • p: long localized time
  • Characters are escaped using single quote symbols (').

Example

// Escape string by single quote characters:
var result = format("15:00:00.000", "h 'o''clock'")
//=> "3 o'clock"

chain()

chain(time): ITimeChain

Parameters

time

Time

Returns

ITimeChain