Convert Date to format given by pattern
Examples
var hrt = ; console;// -> 00:00 console;// -> Now is 1970 year // Default patternconsole;// -> 00:00 01/01/1970 // Day/month string patternsconsole;// -> Today is Thursday // Relative patternconsole;// -> 45 years ago
Currying is also supported!
var hrt = ; // You can use date, pattern and both in constructorvar clock = 'hh:mm'; console;// -> 00:00
Docs
Symbol | Meaning |
---|---|
h | hours |
m | minutes |
s | seconds |
D | day of month |
M | month |
YY | year |
day | day of week |
month | month of year |
relative | relative time |
12h | Force AM/PM position |
Symbols can be used twice, it will add 0 if number less than 10, for example:
console;// -> 1 console;// -> 01
But year can only be used in %YY%
or %YYYY%
variants.
Options
- shortDay - Return first 3 letters of day for %day% pattern
- shortTime - Return time in 12-hour format(you can specify %12h% option to force using 'PM'/'AM' in specific place)
License
MIT © Konstantin Azizov