A simple clean way to format dates with Javascript
Setup
npm install simple-format-date
Usage
; // default output; // => '1973-01-02' // using a string as template; // => '02/01/1973' (italian format) // using a function as templateconst months = '01': 'January' '02': 'February' '03': 'March' '04': 'April' '05': 'May' '06': 'June' '07': 'July' '08': 'August' '09': 'September' '10': 'October' '11': 'November' '12': 'December'; ; // => '02, January 1973'
API
where:
date
the date to formatoptions
template: string | (locals: Object) => string
the format to use in ejs syntax (default<%= YY %>-<%= MM %>-<%= DD %>
) wherelocals
is an object containing the following keys:Y
short year ('15'
for 2015)YY
numeric long year (2015
)M
numeric month (9
for September)MM
padded month ('09'
for September)D
numeric dayDD
padded dayh
numeric hourshh
padded hoursm
numeric minutesmm
padded minutess
numeric secondsss
padded seconds or a function returning a template