time()
time(input, options?): Time
time(input, zone?): Time
time(hour, minute?, second?): TimeCreates a Time from a clock string, whole-number clock parts, a fields object, or a timestamp. Missing inputs throw a TypeError instead of defaulting to the current clock.
import { datetime, time } from 'native-dates';
const morning = time('9am');
const closing = time('5:30pm');
const iso = time('17:30:00');
const fromNumbers = time(9, 30);
const fromFields = time({ hour: 17, minute: 30, millisecond: 250 });
const fromInstant = time('2026-11-16T17:30:00Z', 'America/New_York');
const fromMoment = time(datetime('2026-11-16T17:30:00Z'), 'Europe/Berlin');
const fromTemporal = time(Temporal.PlainTime.from('08:15'));
closing.toString(); // '17:30:00'
fromInstant.toString(); // '12:30:00'
fromMoment.toString(); // '18:30:00'Parameters
Clock string, fields object, existing time or timestamp, or 24-hour hour from 0 to 23.
Time zone or options object when reading a timestamp or loose string, or minute from 0 to 59.
4 options
Time zone used to extract the time of day from an instant string, DateTime, or Date.
BCP 47 locale tag carried on the returned Time and every value derived from it.
falseRead informal date-time strings and return null on unreadable input with @native-dates/plugins/loose.
Override the active locale's numeric date order when loose mode parses a date-and-time string.
Whole second from 0 to 59 when passing numbers. Write sub-second digits in a string or fields object.
Returns
A Time representing a time of day, or null when loose mode cannot read input.
When the loose plugin is loaded, loose mode parses localized day-period clocks, dotted clocks in locales that use them, and informal timestamp strings, returning null on unreadable input:
import { time } from 'native-dates';
import '@native-dates/plugins/loose';
time('오후 2:30', { loose: true, locale: 'ko' })?.toString(); // '14:30:00'
time('14.30', { loose: true, locale: 'fi' })?.toString(); // '14:30:00'
time('Mon, 16 Nov 2026 17:30:00 GMT', {
zone: 'America/New_York',
loose: true,
})?.toString(); // '12:30:00'
time('whenever', { loose: true }); // null