CLI for printing dates via momentjs.
$ npm install -g moment-cli
$ moment --help
Usage: moment <input> [options]
Options:
-h, --help output usage information
-V, --version output the version number
-i, --inputFormat <format> e.g: "MM-DD-YYYY". Special handling for "unix".
-f, --format <format> Output format. See momentjs docs for options.
-t, --timeago Output in `timeago` format (fromNow).
-c, --calendar Output in `calendar` format.
-u, --unix Output a unix timestamp (secs since Epoch).
-j, --js Ouput a JavaScript timestamp (ms since Epoch).
Output current time
$ moment
2013-03-11T16:45:21-07:00
Output current time in a custom format
$ moment -f "dddd, MMMM Do YYYY, h:mm:ss a"
Monday, March 11th 2013, 4:46:42 pm
Convert a JavaScript timestamp (ms since Epoch) to a custom format
$ moment 1318781876406 -f MM/DD/YYYY
10/16/2011
Convert a Unix timestamp to a formatted date
$ moment 1318781876 -i unix
2011-10-16T09:17:56-07:00
Convert a date string into a JavaScript timestamp
$ moment 03/11/2011
1299830400000
Convert a date string into a unix timestamp
$ moment 03/11/2011 -u
1299830400
Token | Output | |
---|---|---|
Month | M | 1 2 ... 11 12 |
Mo | 1st 2nd ... 11th 12th | |
MM | 01 02 ... 11 12 | |
MMM | Jan Feb ... Nov Dec | |
MMMM | January February ... November December | |
Day of Month | D | 1 2 ... 30 30 |
Do | 1st 2nd ... 30th 31st | |
DD | 01 02 ... 30 31 | |
Day of Year | DDD | 1 2 ... 364 365 |
DDDo | 1st 2nd ... 364th 365th | |
DDDD | 001 002 ... 364 365 | |
Day of Week | d | 0 1 ... 5 6 |
do | 0th 1st ... 5th 6th | |
ddd | Sun Mon ... Fri Sat | |
dddd | Sunday Monday ... Friday Saturday | |
Week of Year | w | 1 2 ... 52 53 |
wo | 1st 2nd ... 52nd 53rd | |
ww | 01 02 ... 52 53 | |
ISO Week of Year | W | 1 2 ... 52 53 |
Wo | 1st 2nd ... 52nd 53rd | |
WW | 01 02 ... 52 53 | |
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 | |
ss | 00 01 ... 58 59 | |
Timezone | z or zz |
EST CST ... MST PST
Note: as of 1.6.0, the z/zz format tokens have been deprecated. Read more about it here. |
Z | -07:00 -06:00 ... +06:00 +07:00 | |
ZZ | -0700 -0600 ... +0600 +0700 | |
Unix Timestamp | X | 1360013296 |
Developed by Terra Eclipse
Terra Eclipse, Inc. is a nationally recognized political technology and strategy firm located in Aptos, CA and Washington, D.C.
Copyright (C) 2012 Terra Eclipse, Inc. (http://www.terraeclipse.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.