The way Moment
uses dates and times is by wrapping the existing Date()
object in a moment()
object and specifying useful and intuitive methods on this object.
moment().format('MMMM Do YYYY, h:mm:ss a'); // August 4th 2016, 10:41:45 am
moment().format('dddd'); // Thursday
moment().format("MMM Do YY"); // Aug 4th 16
moment().format('YYYY [escaped] YYYY'); // 2016 escaped 2016
moment().format(); // 2016-08-04T10:41:45+02:00
moment("20111031", "YYYYMMDD").fromNow(); // 5 years ago
moment("20120620", "YYYYMMDD").fromNow(); // 4 years ago
moment().startOf('day').fromNow(); // 11 hours ago
moment().endOf('day').fromNow(); // in 13 hours
moment().startOf('hour').fromNow(); // 42 minutes ago
moment().subtract(10, 'days').calendar(); // 07/25/2016
moment().subtract(6, 'days').calendar(); // Last Friday at 10:42 AM
moment().subtract(3, 'days').calendar(); // Last Monday at 10:42 AM
moment().subtract(1, 'days').calendar(); // Yesterday at 10:42 AM
moment().calendar(); // Today at 10:42 AM
moment().endOf('day'); // Today at 23:59 AM
moment().add(1, 'days').calendar(); // Tomorrow at 10:42 AM
moment().add(3, 'days').calendar(); // Sunday at 10:42 AM
moment().add(10, 'days').calendar(); // 08/14/2016
moment.locale(); // en
moment().format('LT'); // 10:43 AM
moment().format('LTS'); // 10:43:14 AM
moment().format('L'); // 08/04/2016
moment().format('l'); // 8/4/2016
moment().format('LL'); // August 4, 2016
moment().format('ll'); // Aug 4, 2016
moment().format('LLL'); // August 4, 2016 10:43 AM
moment().format('lll'); // Aug 4, 2016 10:43 AM
moment().format('LLLL'); // Thursday, August 4, 2016 10:43 AM
moment().format('llll'); // Thu, Aug 4, 2016 10:43 AM