Skip to content

formatDate

Formats a date using date-fns format tokens. Interprets the input as UTC.

Type: transform

Aliases

dateFormat

Parameters

  • input (union): The input date as an ISO string or milliseconds since epoch.
  • format (string): The date-fns format string.

Returns

Type: string

The formatted date string, or null if the input is invalid.

Examples

javascript
formatDate("2024-01-15T00:00:00.000Z", "yyyy-MM") // "2024-01"
javascript
"2024-06-15T00:00:00.000Z"|formatDate("LLLL") // "June"
javascript
"2024-03-25T00:00:00.000Z"|formatDate("EEEE") // "Monday"

Released under the MIT License.