Creates a CalendarDate from a year-first date string, three 1-indexed numbers, a fields object, or an existing date or timestamp. Impossible dates such as February 30 throw a RangeError instead of rolling into March.
Months always run from 1 for January through 12 for December, unlike JavaScript’s zero-indexed Date constructor. Inputs with a year and month but no day throw a RangeError instead of inventing the first of the month, so use yearMonth() for month values.
Input
Example
How it reads
Year-first date string
'2026-11-16', '2026/11/6', '2026年11月16日'
Reads a 4-digit year, month, and day with any separator other than Latin letters or colons.
Local date-time string
'2026-11-16T09:30'
Keeps the calendar date and drops the time of day.
ISO instant string
'2026-11-17T02:00:00Z'
Reads the calendar day of that moment in the given zone or configured default.
Year, month, and day
date(2026, 11, 16)
Takes three whole numbers with 1 for January through 12 for December.
Fields object
{ year: 2026, month: 11, day: 16 }
Reads 1-indexed calendar fields and rejects impossible dates.
Extracts the calendar date in the given zone, or in dt.zone when omitted.
JavaScript Date
date(jsDate, 'America/Los_Angeles')
Reads the calendar day of that timestamp in the given zone or configured default.
Temporal value
Temporal.PlainDate, Temporal.Instant
Reads plain dates in any calendar as the same ISO day and shifts instants into the target zone.
Timestamps depend on the time zone
An ISO string with a trailing Z or UTC offset names a moment that can fall on two different calendar days around the world. Pass an explicit zone when extracting a user’s calendar day on a server.
Relative calendar days
Today’s date depends on where you stand on Earth. Each helper below accepts an optional time zone and falls back to your configured default.
today()
today(zone?): CalendarDate
Returns today’s calendar date in the given time zone or your configured default. Late in the evening in the Americas, Asia and Oceania have already crossed midnight into the next calendar date.
Parameters
zoneZone
Time zone whose current calendar date to read, such as 'Asia/Tokyo' or 'America/Los_Angeles'.
Returns
CalendarDate
Today's CalendarDate in zone.
import { datetime, today } from 'native-dates';const inLosAngeles = today('America/Los_Angeles');const inTokyo = today('Asia/Tokyo');// At 02:00 UTC on Nov 17, Los Angeles is still on Nov 16 while Tokyo is on Nov 17const moment = '2026-11-17T02:00:00Z';datetime(moment, 'America/Los_Angeles').date.toString(); // '2026-11-16'datetime(moment, 'Asia/Tokyo').date.toString(); // '2026-11-17'
tomorrow()
tomorrow(zone?): CalendarDate
Returns tomorrow’s calendar date in the given time zone, one calendar day after today(zone).