date date and time library
date date and time library
Function
date() creates a local time zone Date object; supports date string parsing, chrono/strftime style formatting, Unix timestamp conversion, date operations, and reading of fields such as year, month, day, hour, minute, and second.
Syntax
date() date(timestamp) date(text)
Parameters
| Parameter | Type | Required | Default value | Description |
|---|---|---|---|---|
| timestamp | Int/Float | No | None | Second level Unix timestamp; if no parameters are passed, the current local time is returned. |
| text | String | No | None | Date string or second-level Unix timestamp string. |
Return Value
| Type | Description |
|---|---|
| Date | Returns the local time zone Date object. |
API List
| API | Description |
|---|---|
| Date.format | Output date and time according to format string. |
| Date.from_string | Parses a date string and creates a new Date object. |
| Date.from_timestamp | Creates a new Date object from a Unix timestamp in seconds. |
| Date.from_millis | Create a new Date object from a millisecond Unix timestamp. |
| Date.from_micros | Creates a new Date object from a microsecond Unix timestamp. |
| Date.from_nanos | Creates a new Date object from a nanosecond Unix timestamp. |
| Date.add | Returns a new Date object plus or minus the specified time. |
| Date.diff | Returns the difference between two dates converted in the specified unit. |
| Date.start_of_day | Returns a new Date object at zero o'clock on the day. |
| Date.timestamp | Read second-level Unix timestamp. |
| Date.timestamp_millis | Read millisecond-level Unix timestamp. |
| Date.timestamp_micros | Read microsecond-level Unix timestamp. |
| Date.timestamp_nanos | Read a nanosecond Unix timestamp. |
| Date.year | Read the year. |
| Date.month | Read the month. |
| Date.day | Read the day of the month. |
| Date.hour | Read the hour. |
| Date.minute | Read minutes. |
| Date.second | Read seconds. |
| Date.millis | Read the millisecond part of the current second. |
| Date.micros | Read the microsecond part of the current second. |
| Date.nanos | Read the nanosecond part of the current second. |
| Date.weekday | Read the weekday number. |
| Date.week | Read the ISO week number. |
| Date.yearday | Read the date serial number in a year. |
| Date.quarter | Read quarter. |
| Date.to_string | Output the date and time in the default format. |
Code Examples
// Output: 2026-06-09 10:11 print date().format('%Y-%m-%d %H:%M') d = date('2026-06-09 10:11:12') result = { text: d.format('%Y-%m-%d'), timestamp: d.timestamp(), quarter: d.quarter() }
Notes
- No parameters date() returns the current local time.
- String parameters will be parsed into Date according to common date formats, and date('%Y-%m-%d') is no longer supported to directly format the current time.
- To format the current time, use date().format('%Y-%m-%d').