Loading || Installing
html |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script> |
cdn |
|
npm |
npm install moment |
bower |
bower install moment |
git |
|
WWW |
|
Parsing
Now |
moment() |
String |
moment("1977-09-05", "YYYY-MM-DD") |
Unix |
moment.unix(0123456789) |
Object |
moment({year: 1977[, month, day, hour, minute, second]}) |
Array |
moment([year, month, day, hour, minute, second, ms]) |
Get/Set
Second |
.second() / .second(/*0-59*/) |
Minute |
.minute() / .minute(/*0-59*/) |
Hour |
.hour() / .hour(/*0-23*/) |
Day of Week |
.day() / .day(/*0-6*/) |
Day of Month |
.date() / .date(/*1-31*/) |
Day of Year |
.dayOfYear() / .dayOfYear.day(/*0-366*/) |
Week of Year |
.week() / week(/*1-53*/) |
Month |
.month() / .month(/*Jan || 1*/) |
Year |
.year() / .year(/*####*/) |
Zones
Convert to UTC |
moment().utc() |
Get UTC Offset |
moment().utcOffset() |
Set UTC Offset |
.utcOffset(Number) |
|
|
Formatting
Datetime |
.format("YYYY-MM-DD HH:mm:ssZ") |
Year |
YY [15], YYYY [2015] |
Month Numeric |
M [1+], MM [01+] |
Month Alpha |
MMM [Jan+], MMMM [January+] |
Day of Month |
D [1+], Do [1st+], DD [01+] |
Day of Year |
DDD [1+], DDDo [1st+], DDDD [001+] |
Day of Week |
d [0+], dd [Su+], ddd [Sun+], dddd [Sunday+] |
Hour 24h-Clock |
H [0+], HH [00+] |
Hour 12h-clock |
h [1+], hh [01+] |
Minute |
m [00+], mm [00+] |
Second |
s [0+], ss [00+] |
Second, Fractional |
S [0-9], SS [00-99] |
Zone |
Z [-00:00], ZZ [-0000] |
Unix Timestamp |
X [0123456789] |
Unix Millisecond |
x [0123456789012] |
master these: Y, M, D, H, m, s, Z, X
Manipulate, Constrain, or Validate
Get Start of Period |
.startOf(String) ['week'] |
Get End of Period |
.endOf(String) ['week'] |
$DateA Is Before $DateB |
.isBefore(String[, String]) ["1977-09-05", "year"] |
$DateA Is After$DateB |
.isAfter(String[, String]) ["1977-09-05", "year"] |
$DateA Is the Same as $DateB |
.isSame(String[, String]) ["1977-09-05", "year"] |
$DateA Is Between $DateB |
.isBetwee(String, String[, String]) |
Add Time to Date |
.add(Number, String) [4, 'days'] |
Subtract Time from Date |
.subtract(Number, String) [4, 'days'] |
Constrain Max |
.max(Object) [moment().add(1, 'day')] |
Constrain Min |
.min(Object) [moment().subtract(1, 'day')] |
Format to String |
.format(String) ["YY-MM-DD"] |
Check Validity |
momentObject.isValid() |
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment