Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

format

import { format } from "https://esm.sh/v135/date-fns@3.6.0/index.d.mts";
@example
// Represent 11 February 2014 in middle-endian format:
const result = format(new Date(2014, 1, 11), 'MM/dd/yyyy')
//=> '02/11/2014'
@example
// Represent 2 July 2014 in Esperanto:
import { eoLocale } from 'date-fns/locale/eo'
const result = format(new Date(2014, 6, 2), "do 'de' MMMM yyyy", {
  locale: eoLocale
})
//=> '2-a de julio 2014'
@example
// Escape string by single quote characters:
const result = format(new Date(2014, 6, 2, 15), "h 'o''clock'")
//=> "3 o'clock"
function format<DateType extends Date>(
date: DateType | number | string,
formatStr: string,
options?: FormatOptions,
): string;
§
format<DateType extends Date>(date: DateType | number | string, formatStr: string, options?: FormatOptions): string
[src]

§Type Parameters

§
DateType extends Date
[src]

§Parameters

§
date: DateType | number | string
[src]
  • The original date
§
formatStr: string
[src]
§
options?: FormatOptions optional
[src]
  • An object with options

§Return Type

§
string
[src]

The formatted date string