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.
Example
import { getIsoWeek, nowIso, unixTimestamp } from '@rtorcato/js-common/datetime'
import { secondsBetween } from '@rtorcato/js-common/time'
const started = new Date()
const row = {
createdAt: nowIso(), // '2026-06-12T09:04:07.123Z'
expiresAt: unixTimestamp() + 3600, // seconds, for a JWT `exp`
}
await handleRequest()
secondsBetween(started, new Date()) // elapsed seconds, floored (b - a)
getIsoWeek(new Date('2026-01-01')) // 1
Import
import { formatDateTimeLocal, getIsoWeek, getIsoWeekInfo } from '@rtorcato/js-common/datetime'
Exports
| Name | Summary |
|---|---|
formatDateTimeLocal | Formats a Date as YYYY-MM-DD HH:mm:ss (local time). |
getIsoWeek | Returns the ISO week number (1–53) of a given date using UTC. |
getIsoWeekInfo | Returns ISO week number and ISO week year (which may differ from calendar year). |
getTimezoneOffset | Returns the timezone offset in minutes for a given date (local − UTC). |
nowIso | Returns the current date and time as an ISO string (YYYY-MM-DDTHH:mm:ss.sssZ). |
parseIsoDateTime | Parses an ISO date-time string to a Date object. |
toUtcDate | Returns the UTC equivalent of a local Date. |
unixMillis | Returns the number of milliseconds since the Unix epoch. |
unixTimestamp | Returns the number of seconds since the Unix epoch (UTC). |