Skip to content

constructor

Creates a value for the current local date, time, and offset.

1
new DateTimeOffset(): DateTimeOffset

Creates a new value from a JavaScript Date.

1
new DateTimeOffset(val: Date): DateTimeOffset

Creates a value from milliseconds since the Unix epoch in the local offset.

1
new DateTimeOffset(val: number): DateTimeOffset

Creates a value from an ISO-like or locale-formatted string.

1
new DateTimeOffset(val: string): DateTimeOffset

Creates a new value from calendar components in the local offset of that date.

1
new DateTimeOffset(year: number, month: number, day: number): DateTimeOffset

Creates a new value from local calendar and time components.

1
new DateTimeOffset(year: number, month: number, day: number, hour: number, minute?: number, second?: number, millisecond?: number): DateTimeOffset

Parameters

Date val
    A JavaScript Date object.

number year
    The year (e.g., 2024).

number month
    The month (1-12, where 1 is January).

number day
    The day of the month (1-31).

number hour
    The hour (0-23).

number minute optional
    The minute (0-59).

number second optional
    The second (0-59).

number millisecond optional
    The millisecond (0-999).

Remarks

Components outside their range, such as February 30, throw an error instead of rolling over to the next month.

Examples

Convert a JavaScript date

1
var now = new DateTimeOffset(new Date());

Create the first day of the year

1
var yearStart = new DateTimeOffset(2024, 1, 1);

See Also