ctrl + k
On This Page
Functions
Date Utilities
The Date utilities provide functions for formatting and manipulating dates in JavaScript.
Functions
formatDate
Formats a date according to the specified format string and options.
International Support This function uses
Intl.DateTimeFormat
internally, please refer to the associated docs for details on timezone and formatting usage.
Local Timezone Usage When the ‘local’ keyword is used for the timezone option, the function will use the local timezone of the environment where the code is running. This is particularly useful for displaying dates in the user’s local time without needing to detect the timezone programmatically.
Parameters
Name | Type | Default | Description |
---|---|---|---|
date | Date | The date to format | |
format | string | ’LLL’ | The format string (e.g., ‘YYYY-MM-DD’, ‘LT’, ‘LL’) |
options | object | Additional formatting options |
Options
Name | Type | Default | Description |
---|---|---|---|
locale | string | ’default’ | The locale to use for formatting |
hour12 | boolean | true | Whether to use 12-hour time |
timezone | string | ’UTC’ | The timezone to use. Use ‘local’ for the local timezone. |
Returns
A formatted date string.