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 fromMoment = time(datetime('2026-11-16T17:30:00Z', 'America/New_York'));
const fromTemporal = time(Temporal.PlainTime.from('08:15'));
closing.toString(); // '17:30:00'
fromMoment.toString(); // '12: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 Date or loose string, or minute from 0 to 59.
3 options
Time zone used to extract the time of day from a JavaScript Date or loose timestamp.
falseRead full timestamp strings and return null on unreadable input with @native-dates/plugins/loose.
Interpret ambiguous numeric dates day-first 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 extracts the local clock from full timestamp strings. Unreadable inputs return null instead of throwing:
import { time } from 'native-dates';
import '@native-dates/plugins/loose';
time('2026-11-16T17:30:00Z', { zone: 'America/New_York', loose: true })?.toString(); // '12:30:00'
time('whenever', { loose: true }); // null