easydate
Returns the date according to a pattern.
Installation
$ npm install easydate
Test:
$ npm test
Usage/API
easydate(patternString, [inputDate])
The single exported function has two arguments. The first and only required argument is the pattern string (see Pattern Options below). If only including the pattern string it will return a formatted string for the current date-time, if the optional input date string is supplied, that particular date will be returned formatted. This input date string must be parseable by JavaScript's Date.parse
function; see below for acceptable examples.
Examples:
var easydate = require('easydate');
easydate('d-M-y');
easydate('d/M/Y');
easydate('Y.M.d');
easydate('M');
easydate('d-M-Y @ h:m:s.l');
easydate('d-M-Y @ h:m', '2015-11-03T16:06:00.000Z');
easydate('h:m:s.l', '2015-11-03T16:06:08.123Z');
easydate('M~d~Y', '03-01-2017');
Pattern Options
Case sensitive.
Y
Full year (nnnn)y
Year (nn)M
Month (nn)d
Day (nn)h
Hour (nn)m
Minute (nn)s
Second (nn)l
Millisecond (nnn)
Caveats
Any instances of the above characters will be replaced with the relevant numbers. It is recommended to not use words within the pattern string.
License
MIT