Skip to main content

Datetime

A minimal set of combined date+time helpers built on the native Date — ISO formatting, ISO week numbers, timezone offset, Unix timestamps.

Intentionally minimal

The date, time, and datetime modules cover everyday native-Date work and nothing more. If you need locale-aware formatting, parsing arbitrary formats, durations, calendars, or timezone math, use a dedicated library:

  • date-fns — modular, tree-shakeable, immutable
  • dayjs — 2 KB Moment-style API
  • luxon — IANA timezones, Intl-based formatting, durations

These are stable, well-maintained, and far better than anything a thin helper set can offer.

Import

import {
formatDateTimeLocal,
getIsoWeek,
getIsoWeekInfo,
getTimezoneOffset,
nowIso,
parseIsoDateTime,
secondsBetween,
toUtcDate,
unixMillis,
unixTimestamp,
} from '@rtorcato/js-common/datetime'

Exports

NameSummary
formatDateTimeLocalFormats a Date as YYYY-MM-DD HH:mm:ss (local time).
getIsoWeekReturns the ISO week number (1–53) of a date (UTC).
getIsoWeekInfoReturns ISO week number and ISO week year (may differ from calendar year).
getTimezoneOffsetReturns the timezone offset in minutes for a date (local − UTC).
nowIsoReturns the current date and time as an ISO string.
parseIsoDateTimeParses an ISO date-time string to a Date object.
secondsBetweenReturns the difference in seconds between two Date objects.
toUtcDateReturns the UTC equivalent of a local Date.
unixMillisReturns the number of milliseconds since the Unix epoch.
unixTimestampReturns the number of seconds since the Unix epoch (UTC).

Full reference

See the datetime API reference for individual function signatures.