Use these examples when app code receives date strings from forms, APIs, route params, or persisted state.
Timestamp does not need a UI playground like CodePen because the package has no visual component. The useful examples are small, copyable TypeScript flows with known output.
Parse common inputs
import { function getDate(timestamp: Timestamp): stringFormats the date portion of a Timestamp object.getDate, function getDateTime(timestamp: Timestamp): stringFormats a Timestamp as date plus time.getDateTime, function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp } from '@timestamp-js/core'
const const dateOnly: TimestampdateOnly = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp('2026-06-08')!
const const dateTime: TimestampdateTime = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp('2026-06-08 09:30')!
const const iso: Timestampiso = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp('2026-06-08T09:30:15.250Z')!
function getDate(timestamp: Timestamp): stringFormats the date portion of a Timestamp object.getDate(const dateOnly: TimestampdateOnly) // "2026-06-08"
function getDateTime(timestamp: Timestamp): stringFormats a Timestamp as date plus time.getDateTime(const dateTime: TimestampdateTime) // "2026-06-08 09:30"
function getDateTime(timestamp: Timestamp): stringFormats a Timestamp as date plus time.getDateTime(const iso: Timestampiso) // "2026-06-08 09:30:15.250Z"Preserve timezone suffixes
Timestamp keeps parsed wall-clock fields stable. Timezone suffixes are stored on the object, but parsing does not convert the date or time into the local runtime timezone.
import { function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp } from '@timestamp-js/core'
const const timestamp: Timestamptimestamp = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp('2026-06-08T09:30:15-07:00')!
const timestamp: Timestamptimestamp.Timestamp.hour: numberHour in 24-hour format.hour // 9
const timestamp: Timestamptimestamp.Timestamp.minute: numberMinute of the hour.minute // 30
const timestamp: Timestamptimestamp.Timestamp.timezone?: string | undefinedOptional parsed ISO timezone suffix such as `Z`, `+06:00`, or `-0700`.
The suffix is preserved for callers, but parsing does not convert the
wall-clock values into another timezone.timezone // "-07:00"Convert native Date values explicitly
Use parseDate() when the input is already a JavaScript Date and you want host-local fields. Use parseDateUTC() when the Date represents an instant and you want UTC fields.
import { function getDateTime(timestamp: Timestamp): stringFormats a Timestamp as date plus time.getDateTime, function parseDate(date: Date): Timestamp | nullConverts a JavaScript Date into a formatted Timestamp using host-local fields.
Use parseDateUTC() when the Date represents an instant that should be read
with UTC getters instead of host-local getters.parseDate, function parseDateUTC(date: Date): Timestamp | nullConverts a JavaScript Date into a formatted Timestamp using UTC fields.
Use this when server and client output should agree on the same UTC calendar
and time fields for a native Date instant.parseDateUTC } from '@timestamp-js/core'
const const instant: Dateinstant = new var Date: DateConstructor
new (value: number | string | Date) => Date (+4 overloads)
Date('2026-06-08T09:30:00.000Z')
const const localTimestamp: TimestamplocalTimestamp = function parseDate(date: Date): Timestamp | nullConverts a JavaScript Date into a formatted Timestamp using host-local fields.
Use parseDateUTC() when the Date represents an instant that should be read
with UTC getters instead of host-local getters.parseDate(const instant: Dateinstant)!
const const utcTimestamp: TimestamputcTimestamp = function parseDateUTC(date: Date): Timestamp | nullConverts a JavaScript Date into a formatted Timestamp using UTC fields.
Use this when server and client output should agree on the same UTC calendar
and time fields for a native Date instant.parseDateUTC(const instant: Dateinstant)!
function getDateTime(timestamp: Timestamp): stringFormats a Timestamp as date plus time.getDateTime(const localTimestamp: TimestamplocalTimestamp) // Depends on the host timezone.
function getDateTime(timestamp: Timestamp): stringFormats a Timestamp as date plus time.getDateTime(const utcTimestamp: TimestamputcTimestamp) // "2026-06-08 09:30"Parse time-only values
Use parseTime() for controls or APIs that only carry time-of-day data.
import { function parseTime(input: number | string | {
hour: number;
minute: number;
}): number | false
Converts time input into minutes since midnight.
Strings may include seconds or milliseconds, but sub-minute precision is
ignored for this minute-oriented helper.parseTime } from '@timestamp-js/core'
function parseTime(input: number | string | {
hour: number;
minute: number;
}): number | false
Converts time input into minutes since midnight.
Strings may include seconds or milliseconds, but sub-minute precision is
ignored for this minute-oriented helper.parseTime('09') // 540
function parseTime(input: number | string | {
hour: number;
minute: number;
}): number | false
Converts time input into minutes since midnight.
Strings may include seconds or milliseconds, but sub-minute precision is
ignored for this minute-oriented helper.parseTime('09:30:15.250') // 570Format individual pieces
Use getDate(), getTime(), and getDateTime() when you need stable string output for inputs, route params, storage, or display.
import { function getDate(timestamp: Timestamp): stringFormats the date portion of a Timestamp object.getDate, function getDateTime(timestamp: Timestamp): stringFormats a Timestamp as date plus time.getDateTime, function getTime(timestamp: Timestamp): stringFormats the time portion of a Timestamp object.
Minute precision is formatted as `HH:mm`; second precision as `HH:mm:ss`;
millisecond precision as `HH:mm:ss.SSS`.getTime, function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp } from '@timestamp-js/core'
const const timestamp: Timestamptimestamp = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp('2036-06-08T09:30:15.250Z')!
function getDate(timestamp: Timestamp): stringFormats the date portion of a Timestamp object.getDate(const timestamp: Timestamptimestamp) // "2036-06-08"
function getTime(timestamp: Timestamp): stringFormats the time portion of a Timestamp object.
Minute precision is formatted as `HH:mm`; second precision as `HH:mm:ss`;
millisecond precision as `HH:mm:ss.SSS`.getTime(const timestamp: Timestamptimestamp) // "09:30:15.250"
function getDateTime(timestamp: Timestamp): stringFormats a Timestamp as date plus time.getDateTime(const timestamp: Timestamptimestamp) // "2036-06-08 09:30:15.250"Refresh formatted fields after custom transforms
Most helpers already return formatted timestamps. Reach for updateFormatted() only when you intentionally build or alter a timestamp-like object yourself.
import { function copyTimestamp(timestamp: Timestamp): TimestampReturns an immutable copy of a Timestamp object.copyTimestamp, function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp, function updateFormatted(timestamp: Timestamp): TimestampUpdates the passed Timestamp with formatted data (time string, date string, weekday, day of year and workweek)updateFormatted } from '@timestamp-js/core'
const const source: Timestampsource = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp('2036-06-08 09:30')!
const const copied: Timestampcopied = function copyTimestamp(timestamp: Timestamp): TimestampReturns an immutable copy of a Timestamp object.copyTimestamp(const source: Timestampsource)
const const refreshed: Timestamprefreshed = function updateFormatted(timestamp: Timestamp): TimestampUpdates the passed Timestamp with formatted data (time string, date string, weekday, day of year and workweek)updateFormatted({ ...const copied: Timestampcopied, Timestamp.hour: numberHour in 24-hour format.hour: 14, Timestamp.minute: numberMinute of the hour.minute: 45 })
const refreshed: Timestamprefreshed.Timestamp.time?: string | undefinedFormatted time string.
Minute precision is formatted as `HH:mm`; second precision as `HH:mm:ss`;
millisecond precision as `HH:mm:ss.SSS`.time // "14:45"
const copied: Timestampcopied.Timestamp.time?: string | undefinedFormatted time string.
Minute precision is formatted as `HH:mm`; second precision as `HH:mm:ss`;
millisecond precision as `HH:mm:ss.SSS`.time // "09:30"Convert back to native Date values
Use UTC output when the Date represents a portable instant. Use local output when you specifically need host-local Date behavior.
import {
function getDateObject(timestamp: Timestamp): DateConverts a Timestamp to a local JavaScript Date.
This is equivalent to `makeDateTime(timestamp)`.getDateObject,
function makeDate(timestamp: Timestamp): DateConverts a Timestamp date into a host-local JavaScript Date.makeDate,
function makeDateTime(timestamp: Timestamp): DateConverts a Timestamp date and time into a host-local JavaScript Date.makeDateTime,
function makeDateTimeUTC(timestamp: Timestamp): DateConverts a Timestamp date and time into a UTC JavaScript Date.makeDateTimeUTC,
function makeDateUTC(timestamp: Timestamp): DateConverts a Timestamp date into a UTC JavaScript Date.makeDateUTC,
function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp,
} from '@timestamp-js/core'
const const timestamp: Timestamptimestamp = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp('2036-06-08 09:30')!
function makeDate(timestamp: Timestamp): DateConverts a Timestamp date into a host-local JavaScript Date.makeDate(const timestamp: Timestamptimestamp).Date.getHours(): numberGets the hours in a date, using local time.getHours() // 0
function makeDateTime(timestamp: Timestamp): DateConverts a Timestamp date and time into a host-local JavaScript Date.makeDateTime(const timestamp: Timestamptimestamp).Date.getMinutes(): numberGets the minutes of a Date object, using local time.getMinutes() // 30
function makeDateUTC(timestamp: Timestamp): DateConverts a Timestamp date into a UTC JavaScript Date.makeDateUTC(const timestamp: Timestamptimestamp).Date.toISOString(): stringReturns a date as a string value in ISO format.toISOString() // "2036-06-08T00:00:00.000Z"
function makeDateTimeUTC(timestamp: Timestamp): DateConverts a Timestamp date and time into a UTC JavaScript Date.makeDateTimeUTC(const timestamp: Timestamptimestamp).Date.toISOString(): stringReturns a date as a string value in ISO format.toISOString() // "2036-06-08T09:30:00.000Z"
const const localDate: DatelocalDate = function getDateObject(timestamp: Timestamp): DateConverts a Timestamp to a local JavaScript Date.
This is equivalent to `makeDateTime(timestamp)`.getDateObject(const timestamp: Timestamptimestamp)
const localDate: DatelocalDate instanceof var Date: DateConstructorEnables basic storage and retrieval of dates and times.Date // trueType your application boundaries
Import types from the same package when your app accepts or returns Timestamp values.
import { function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp } from '@timestamp-js/core'
import type { const TimeObject: TimeObjectTime-only value used when callers need hour/minute input without a date.
Frozen empty time-object template.TimeObject, const Timestamp: TimestampImmutable timestamp data used by all parser, comparison, and date math helpers.
Timestamps use Gregorian calendar fields and preserve optional ISO timezone
suffixes without converting the wall-clock values into another zone.
Frozen empty timestamp template.
Use copyTimestamp or parser helpers to create new timestamp objects
instead of mutating this shared default.Timestamp } from '@timestamp-js/core'
function function asStorageKey(timestamp: Timestamp): stringasStorageKey(timestamp: Timestamptimestamp: Timestamp): string {
return `${timestamp: Timestamptimestamp.Timestamp.date: stringDate string in `YYYY-MM-DD` form when the timestamp has a day.date} ${timestamp: Timestamptimestamp.Timestamp.time?: string | undefinedFormatted time string.
Minute precision is formatted as `HH:mm`; second precision as `HH:mm:ss`;
millisecond precision as `HH:mm:ss.SSS`.time ?? '00:00'}`
}
function function toMinutes(time: TimeObject): numbertoMinutes(time: TimeObjecttime: TimeObject): number {
return time: TimeObjecttime.TimeObject.hour: numberHour in 24-hour format.hour * 60 + time: TimeObjecttime.TimeObject.minute: numberMinute of the hour.minute
}
const const timestamp: Timestamptimestamp = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | nullConverts a supported date or date-time string into a formatted Timestamp object.
If `now` is supplied, the returned timestamp also includes relative flags
such as `past`, `current`, `future`, and `currentWeekday`.parseTimestamp('2036-06-08 09:30')!
function asStorageKey(timestamp: Timestamp): stringasStorageKey(const timestamp: Timestamptimestamp) // "2036-06-08 09:30"
function toMinutes(time: TimeObject): numbertoMinutes({ TimeObject.hour: numberHour in 24-hour format.hour: 9, TimeObject.minute: numberMinute of the hour.minute: 30 }) // 570