native-dates

API / Functions

date() function

Create a CalendarDate from a year-first date string, year-month-day numbers, fields, or the current day.

import { date, today } from 'native-dates'core 14.9 kB min+br

Reading calendar dates

date()

date(input, options?): CalendarDate
date(input, zone?): CalendarDate
date(year, month, day): CalendarDate

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.

create.js
import { date, datetime } from 'native-dates';

const fromIso = date('2026-11-16');
const fromSlashes = date('2026/11/6');
const fromNumbers = date(2026, 11, 16);
const fromFields = date({ year: 2026, month: 11, day: 16 });
const fromMoment = date(datetime('2026-11-17T02:00:00Z', 'America/Los_Angeles'));

fromSlashes.toString(); // '2026-11-06'
fromMoment.toString(); // '2026-11-16'
inputCalendarDateInput | numberrequired

ISO date string, fields object, existing date or timestamp, or the 4-digit year.

optionsZone | ReadOptions | number

Time zone or options object when reading a timestamp or loose string, or 1-indexed month from 1 to 12.

4 options
zoneZone

Time zone used to determine the calendar day of an instant string, DateTime, or Date.

localeLocale

BCP 47 locale tag carried on the returned CalendarDate and every value derived from it.

loosebooleandefault false

Parse informal date strings and return null on unreadable input with @native-dates/plugins/loose.

dayFirstboolean

Override the active locale's numeric date order for strings like '07.09.2026' in loose mode.

daynumber

Day of the month from 1 to 31 when passing year, month, and day.

CalendarDate

A CalendarDate with no clock or zone, or null when loose mode cannot read input.

When reading an ISO timestamp or native JavaScript Date, pass a time zone to choose which location’s calendar day to extract:

date('2026-11-17T02:00:00Z', 'America/Los_Angeles').toString(); // '2026-11-16'
date('2026-11-17T02:00:00Z', 'Asia/Tokyo').toString(); // '2026-11-17'

Accepted inputs

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.
DateTime date(dt, 'Asia/Tokyo') 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.

zoneZone

Time zone whose current calendar date to read, such as 'Asia/Tokyo' or 'America/Los_Angeles'.

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 17
const 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).

zoneZone

Time zone whose calendar to advance from today.

CalendarDate

Tomorrow's CalendarDate in zone.

import { tomorrow } from 'native-dates';

const nextDay = tomorrow();
const londonTomorrow = tomorrow('Europe/London');

yesterday()

yesterday(zone?): CalendarDate

Returns yesterday’s calendar date in the given time zone, one calendar day before today(zone).

zoneZone

Time zone whose calendar to step back from today.

CalendarDate

Yesterday's CalendarDate in zone.

import { yesterday } from 'native-dates';

const priorDay = yesterday();
const londonYesterday = yesterday('Europe/London');
Edit this pageUpdated Nov 22, 2026