[github地点:https://github.com/ABCDdouyae…]
fecha
比moment.js越发轻量级的时候剖析和格式化包
format
用法:
format(<Date Object|String|timestamp>, <String Format>)
返回:
string
const fecha = require('fecha');
fecha.format(new Date('2018','3','23','12','0','0'), 'YYYY-MM-DD HH-mm-ss dddd');
//2018-04-23 12-00-00 Monday
fecha.format(12312312, 'YYYY/MM/DD HH-mm-ss dddd');
//1970/01/01 11-25-12 Thursday
parse
用法:
format(String, <String Format>)
返回:
<Date Object>
fecha.parse('February 3rd, 2014', 'MMMM Do, YYYY');
// 2014-02-02T16:00:00.000Z
fecha.parse('10-12-10 14:11:12', 'YY-MM-DD HH:mm:ss');
//2010-12-10T06:11:12.000Z
Token | Output | |
---|---|---|
Month | M | 1 2 … 11 12 |
MM | 01 02 … 11 12 | |
MMM | Jan Feb … Nov Dec | |
MMMM | January February … November December | |
Day of Month | D | 1 2 … 30 31 |
Do | 1st 2nd … 30th 31st | |
DD | 01 02 … 30 31 | |
Day of Week | d | 0 1 … 5 6 |
ddd | Sun Mon … Fri Sat | |
dddd | Sunday Monday … Friday Saturday | |
Year | YY | 70 71 … 29 30 |
YYYY | 1970 1971 … 2029 2030 | |
AM/PM | A | AM PM |
a | am pm | |
Hour | H | 0 1 … 22 23 |
HH | 00 01 … 22 23 | |
h | 1 2 … 11 12 | |
hh | 01 02 … 11 12 | |
Minute | m | 0 1 … 58 59 |
mm | 00 01 … 58 59 | |
Second | s | 0 1 … 58 59 |
ss | 00 01 … 58 59 | |
Fractional Second | S | 0 1 … 8 9 |
SS | 0 1 … 98 99 | |
SSS | 0 1 … 998 999 | |
Timezone | ZZ | -0700 -0600 … +0600 +0700 |