Time
ฦฌ Time: Format
["hh:mm:ss[.sss]"
] & string
An Iso.Time
represents a wall-clock time, with a precision in milliseconds, and 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.
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.
Defined in
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
Name | Type | Description |
---|---|---|
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.
Defined in
fromNumbers
โธ fromNumbers(hour?
, minute?
, second?
, millisecond?
): Time
Parameters
Name | Type |
---|---|
hour? | number |
minute? | number |
second? | number |
millisecond? | number |
Returns
Defined in
isValid
โธ isValid(time
): time is Time
Parameters
Name | Type |
---|---|
time | unknown |
Returns
time is Time
Defined in
assertIsValid
โธ assertIsValid(time
): asserts time is Time
Parameters
Name | Type |
---|---|
time | unknown |
Returns
asserts time is Time
Defined in
getHour
โธ getHour(time
): number
Parameters
Name | Type |
---|---|
time | Time |
Returns
number
Defined in
getMinute
โธ getMinute(time
): number
Parameters
Name | Type |
---|---|
time | Time |
Returns
number
Defined in
getSecond
โธ getSecond(time
): number
Parameters
Name | Type |
---|---|
time | Time |
Returns
number
Defined in
getMillisecond
โธ getMillisecond(time
): number
Parameters
Name | Type |
---|---|
time | Time |
Returns
number
Defined in
with
โธ with(time
, timeLike
, options?
): Time
Parameters
Name | Type |
---|---|
time | Time |
timeLike | Object |
timeLike.hour? | number |
timeLike.minute? | number |
timeLike.second? | number |
timeLike.millisecond? | number |
options? | Object |
options.overflow | TemporalOverflow |
Returns
Defined in
add
โธ add(time
, temporalDurationLike
, options?
): Time
Parameters
Name | Type |
---|---|
time | Time |
temporalDurationLike | Duration | { years? : number ; months? : number ; weeks? : number ; days? : number ; hours? : number ; minutes? : number ; seconds? : number ; milliseconds? : number } |
options? | Object |
options.overflow? | TemporalOverflow |
Returns
Defined in
subtract
โธ subtract(time
, temporalDurationLike
, options?
): Time
Parameters
Name | Type |
---|---|
time | Time |
temporalDurationLike | Duration | { years? : number ; months? : number ; weeks? : number ; days? : number ; hours? : number ; minutes? : number ; seconds? : number ; milliseconds? : number } |
options? | Object |
options.overflow? | TemporalOverflow |
Returns
Defined in
until
โธ until(time
, other
, options?
): Duration
Parameters
Name | Type |
---|---|
time | Time |
other | Time |
options? | Object |
options.largestUnit? | TemporalSingularUnit | TemporalPluralUnit | "auto" |
options.smallestUnit? | TemporalSingularUnit | TemporalPluralUnit |
options.roundingIncrement? | number |
options.roundingMode? | TemporalRoundingMode |
Returns
Defined in
since
โธ since(time
, other
, options?
): Duration
Parameters
Name | Type |
---|---|
time | Time |
other | Time |
options? | Object |
options.largestUnit? | TemporalSingularUnit | TemporalPluralUnit | "auto" |
options.smallestUnit? | TemporalSingularUnit | TemporalPluralUnit |
options.roundingIncrement? | number |
options.roundingMode? | TemporalRoundingMode |
Returns
Defined in
round
โธ round(time
, options
): Time
Parameters
Name | Type |
---|---|
time | Time |
options | Object |
options.smallestUnit | "day" | "hour" | "minute" | "second" | "millisecond" |
options.roundingIncrement? | number |
options.roundingMode? | TemporalRoundingMode |
Returns
Defined in
equals
โธ equals(time
, other
): boolean
Parameters
Name | Type |
---|---|
time | Time |
other | Time |
Returns
boolean
Defined in
toDateTime
โธ toDateTime(time
, date
): DateTime
Parameters
Name | Type |
---|---|
time | Time |
date | Date |
Returns
Defined in
toZonedDateTime
โธ toZonedDateTime(time
, item
): ZonedDateTime
Parameters
Name | Type |
---|---|
time | Time |
item | Object |
item.date | Date |
item.timeZone | string |
Returns
Defined in
getFields
โธ getFields(time
): TimeSlots
Parameters
Name | Type |
---|---|
time | Time |
Returns
TimeSlots
Defined in
from
โธ from(item
, options?
): Time
Parameters
Name | Type |
---|---|
item | any |
options? | Object |
options.overflow | TemporalOverflow |
Returns
Defined in
compare
โธ compare(one
, two
): number
Parameters
Name | Type |
---|---|
one | Time |
two | Time |
Returns
number
Defined in
format
โธ format(time
, format
): string
summary
Format the ZonedDateTime.
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"
Parameters
Name | Type | Description |
---|---|---|
time | Time | the original date |
format | string | the string of tokens |
Returns
string
the formatted date string
Defined in
chain
โธ chain(time
): ITimeChain
Parameters
Name | Type |
---|---|
time | Time |
Returns
ITimeChain