Formatting Date to String and parsing String to Date module for Node.js, RequireJS, and browser.
$ npm install dateformatjs
var DateFormat = require('dateformatjs').DateFormat;
var df = new DateFormat("yyyy'-'MM'-'dd' 'HH':'mm':'ss.fff' 'zzzz");
df.format(new Date());
df.parse('1981-07-04 15:02:06.050 +09:00');
The following specifiers are defined.
Format Specifier | Description | Examples | |
---|---|---|---|
7/4/1981 15:2:6.05 GMT+09:00 | |||
d | The day of the month, from 1 through 31. | 4 | |
dd | The day of the month, from 01 through 31. | 04 | |
ddd | The abbreviated name of the day of the week. | Sat | |
dddd | The full name of the day of the week. | Saturday | |
f | The tenths of a second in a date and time value. | 0 | |
ff | The hundredths of a second in a date and time value. | 05 | |
fff | The milliseconds in a date and time value. | 050 | |
F | If non-zero, the tenths of a second in a date and time value. | (no output) | |
FF | If non-zero, the hundredths of a second in a date and time value. | 05 | |
FFF | If non-zero, the milliseconds in a date and time value. | 050 | |
g | The abbreviated name of period or era. | AD | |
gg | The full name of period or era. | A.D. | |
h | The hour, using a 12-hour clock from 1 to 12. | 3 | |
hh | The hour, using a 12-hour clock from 01 to 12. | 03 | |
H | The hour, using a 24-hour clock from 0 to 23. | 15 | |
HH | The hour, using a 24-hour clock from 00 to 23. | 15 | |
K | Time zone information. | UTC, Local | |
j | Julian day of the year. | 025 | |
m | The minute, from 0 through 59. | 2 | |
mm | The minute, from 00 through 59. | 02 | |
M | The month, from 1 through 12. | 7 | |
MM | The month, from 01 through 12. | 07 | |
MMM | The abbreviated name of the month. | Jul | |
MMMM | The full name of the month. | July | |
s | The second, from 0 through 59. | 6 | |
ss | The second, from 00 through 59. | 06 | |
t | The abbreviated AM/PM designator. | PM | |
tt | The full AM/PM designator. | P.M. | |
y | The year, from 0 to 99. | 1 | |
yy | The year, from 00 to 99. | 81 | |
yyy | The year, with a minimum of three digits. | 1981 | |
yyyy | The year as a four-digit number. | 1981 | |
yyyyy | The year as a five-digit number. | 01981 | |
z | Hours offset from UTC, with no leading zeros. | +9 | |
zz | Hours offset from UTC, with a leading zero for a single-digit value. | +09 | |
zzz | Hours and minutes offset from UTC. | +0900 | |
zzzz | Hours and minutes offset from UTC. | +09:00 | |
"*", '*' | Literal string delimiter. | * | |
"", '' | Double quote and single quote. | ", ' | |
* | Any other character. | * |
Licensed under the MIT license.