Skip to content

API Date

Liu.Yandong.Hanks edited this page Aug 21, 2026 · 4 revisions

Date

Date and time value with component accessors and formatting.

Script API Reference

Overview

Date wraps a .NET date/time value. A date is created from a tick count or from a supported formatted date string, and all component properties are read-only.

String parsing is culture-independent. The host Runtime.DateTimeFormat is tried first when it is configured, followed by the built-in invariant formats:

  • yyyy-MM-dd
  • yyyy-MM-dd HH:mm:ss
  • yyyy-MM-dd HH:mm:ss.fff
  • yyyy-MM-dd HH:mm:ss fff
  • yyyy-MM-ddTHH:mm:ss.fff

Note

The constructor does not read the system clock. Use Date.now() for the current local time or Date.utcNow() for the current UTC time.

Quick Reference

Member Returns Summary
new Date(value) date Creates a date from ticks or a supported date string.
Date.now() date Current local timestamp.
Date.utcNow() date Current UTC timestamp.
Date.parse(value) date Parses a date/time string or tick value.
date.year number Year component.
date.month number Month component, 1 through 12.
date.day number Day-of-month component.
date.hour number Hour component.
date.minute number Minute component.
date.second number Second component.
date.millisecond number Millisecond component.
date.dayOfWeek number Day-of-week component.
date.dayOfYear number Day-of-year component.
date.ticks number Underlying tick value.
date.toString([format]) string Formats the date as text.

Constructors

new Date(value)

Parameters

Name Type Required Description
value number or string Yes Tick count, or date text in a supported format.

Returns

date — the parsed date value.

Behavior

The host Runtime.DateTimeFormat is tried first, then the built-in invariant formats listed in the overview.

Example

var date = new Date("2026-08-19");
return date.year; // 2026

Properties

All Date component properties are read-only numbers.

Property Type Description
date.year number Year component.
date.month number Month component, 1 through 12.
date.day number Day-of-month component.
date.hour number Hour component.
date.minute number Minute component.
date.second number Second component.
date.millisecond number Millisecond component.
date.dayOfWeek number Day-of-week component, as its enumeration number.
date.dayOfYear number Day-of-year component.
date.ticks number Underlying tick value.

Example

var date = new Date("2026-08-19 10:30:45.123");
return date.year + ":" + date.month + ":" + date.day + ":" + date.millisecond; // 2026:8:19:123

Methods

Date.now()

Parameters

None.

Returns

date — the current local timestamp.

Example

return Date.now().year;

Date.utcNow()

Parameters

None.

Returns

date — the current UTC timestamp.

Example

return Date.utcNow().year;

Date.parse(value)

Parameters

Name Type Required Description
value string or number Yes Date text in a supported format, or a tick count.

Returns

date — the parsed date value.

Behavior

The host Runtime.DateTimeFormat is tried first, then the built-in invariant formats.

Warning

Text outside the supported formats is not reliable input. Normalize incoming date strings before parsing them.

Example

return Date.parse("2026-08-19 10:30:00").hour; // 10
var precise = Date.parse("1991-02-01 12:32:55 666");
return precise.millisecond; // 666

date.toString([format])

Parameters

Name Type Required Description
format string No .NET date-format string. Omitting it uses the host Runtime.DateTimeFormat.

Returns

string — the formatted date text.

Example

var date = new Date("2026-08-19");
return date.toString("yyyy/MM/dd"); // "2026/08/19"

Clone this wiki locally