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
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
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
Returns
number
getMinute()
getMinute(
time):number
Parameters
time
Returns
number
getSecond()
getSecond(
time):number
Parameters
time
Returns
number
getMillisecond()
getMillisecond(
time):number
Parameters
time
Returns
number
with()
with(
time,timeLike,options?):Time
Parameters
time
timeLike
hour?
number
minute?
number
second?
number
millisecond?
number
options?
overflow
"constrain" | "reject"
Returns
add()
add(
time,temporalDurationLike,options?):Time
Parameters
time
temporalDurationLike
Duration | { years?: number; months?: number; weeks?: number; days?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }
options?
overflow?
"constrain" | "reject"
Returns
subtract()
subtract(
time,temporalDurationLike,options?):Time
Parameters
time
temporalDurationLike
Duration | { years?: number; months?: number; weeks?: number; days?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }
options?
overflow?
"constrain" | "reject"
Returns
until()
until(
time,other,options?):Duration
Parameters
time
other
options?
largestUnit?
LargestUnit\<TimeUnit>
smallestUnit?
SmallestUnit\<TimeUnit>
roundingIncrement?
number
roundingMode?
RoundingMode
Returns
since()
since(
time,other,options?):Duration
Parameters
time
other
options?
largestUnit?
LargestUnit\<TimeUnit>
smallestUnit?
SmallestUnit\<TimeUnit>
roundingIncrement?
number
roundingMode?
RoundingMode
Returns
round()
round(
time,options):Time
Parameters
time
options
smallestUnit
SmallestUnit\<TimeUnit>
roundingIncrement?
number
roundingMode?
RoundingMode
Returns
equals()
equals(
time,other):boolean
Parameters
time
other
Returns
boolean
isEqual()
isEqual(
time,other):boolean
Parameters
time
other
Returns
boolean
toDateTime()
toDateTime(
time,date):DateTime
Parameters
time
date
Returns
toZonedDateTime()
toZonedDateTime(
time,item):ZonedDateTime
Parameters
time
item
date
timeZone
string
Returns
getFields()
getFields(
time):TimeSlots
Parameters
time
Returns
TimeSlots
from()
from(
item,options?):Time
Parameters
item
string | Partial\<TimeSlots>
options?
overflow
"constrain" | "reject"
Returns
compare()
compare(
one,two):number
Parameters
one
two
Returns
number
format()
format(
time,format,options?):string
Parameters
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:
| Unit | Pattern | Result examples | Notes |
|---|---|---|---|
| AM, PM | a..aa | AM, PM | |
| aaa | am, pm | ||
| aaaa | a.m., p.m. | 1 | |
| aaaaa | a, p | ||
| AM, PM, noon, midnight | b..bb | AM, PM, noon, midnight | |
| bbb | am, pm, noon, midnight | ||
| bbbb | a.m., p.m., noon, midnight | 1 | |
| bbbbb | a, p, n, mi | ||
| Flexible day period | B..BBB | at night, in the morning, ... | |
| BBBB | at night, in the morning, ... | 1 | |
| BBBBB | at night, in the morning, ... | ||
| Hour [1-12] | h | 1, 2, ..., 11, 12 | |
| ho | 1st, 2nd, ..., 11th, 12th | 3 | |
| hh | 01, 02, ..., 11, 12 | ||
| Hour [0-23] | H | 0, 1, 2, ..., 23 | |
| Ho | 0th, 1st, 2nd, ..., 23rd | 3 | |
| HH | 00, 01, 02, ..., 23 | ||
| Hour [0-11] | K | 1, 2, ..., 11, 0 | |
| Ko | 1st, 2nd, ..., 11th, 0th | 3 | |
| KK | 01, 02, ..., 11, 00 | ||
| Hour [1-24] | k | 24, 1, 2, ..., 23 | |
| ko | 24th, 1st, 2nd, ..., 23rd | 3 | |
| kk | 24, 01, 02, ..., 23 | ||
| Minute | m | 0, 1, ..., 59 | |
| mo | 0th, 1st, ..., 59th | 3 | |
| mm | 00, 01, ..., 59 | ||
| Second | s | 0, 1, ..., 59 | |
| so | 0th, 1st, ..., 59th | 3 | |
| ss | 00, 01, ..., 59 | ||
| Fraction of second | S | 0, 1, ..., 9 | |
| SS | 00, 01, ..., 99 | ||
| SSS | 000, 001, ..., 999 | ||
| SSSS | ... | 2 | |
| Long localized time | p | 12:00 AM | 3 |
| pp | 12:00:00 AM | 3 |
Notes:
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'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'These patterns are not in the Unicode Technical Standard #35:
o: ordinal number modifierp: 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
Returns
ITimeChain