date-fns

Methods

(inner) strftime(date, format, options) → {String}

Formats the date by mapping C style formatters to format formatter.

Accepted formatters:

strftime modifier format token
%a ddd
%A dddd
%b MMM
%B MMMM
%d DD
%D MM/DD/YYYY
%e D
%F YYYY-MM-DD
%g WW
%h MMM
%H HH
%I hh
%j DDDD
%k H
%L SSS
%l h
%m MM
%M mm
%p A
%P a
%r hh:mm:ss A
%R HH:MM
%s x
%S ss
%T HH:mm:ss
%u E
%V WW
%w d
%W WW
%y YY
%Y YYYY
%z ZZ
%Z z

All other characters in the string are not changed.

The result may vary by locale.

Parameters:
Name Type Description
date Date | String | Number

The original date.

format String

The string of tokens.

options Object

The object with options, see date-fns/format.

Source:
Returns:

The formatted date string.

Type
String
Examples
// Represent 11 February 2014 in middle-endian format:
const strftime = require("date-fns-strftime");
console.log(strftime(new Date(2014, 1, 11), "%m/%d/%Y"))
//=> "02/11/2014"
// Represent 2 July 2014 in Esperanto:
const eoLocale = require("date-fns/locale/eo");
const strftime = require("date-fns-strftime");
console.log(strftime(new Date(2014, 6, 2), "%d de %B %Y", {locale: eoLocale}))
//=> "2 de julio 2014"