More advanced operations on dates are not so easy, so glad to have solutions like moment.js!
When basic operations and dates and time are quite simple, more advanced like parsing or calculating – aren’t. It’s good to use one of available solutions, such as moment.js! We really like it and often use in various web projects.
Download the library (we can also get locales) or use packages, for example:
bower install moment –save
npm install moment –save
moment().format('MMMM Do YYYY, h:mm:ss a'); // Full date and time
moment().format('dddd'); // Day of week
moment().format("MMM Do YY"); // Date, e.g. May 14th 16
moment().format('YYYY [escaped] YYYY'); // Year - escaped
// => this will simply return e.g. 2016-05-14T15:38:27+02:00
moment("20111031", "YYYYMMDD").fromNow(); // 5 years ago
moment().startOf('day').fromNow(); // 16 hours ago
moment().startOf('hour').fromNow(); // 38 minutes ago
// etc ...
moment().subtract(10, 'days').calendar(); // 05/04/2016
moment().subtract(6, 'days').calendar(); // Last Sunday at 3:38 PM
moment().calendar(); // Today at 3:38 PM
moment().add(1, 'days').calendar(); // Tomorrow at 3:38 PM
moment().add(10, 'days').calendar(); // 05/24/2016
You can adjust all of your cookie settings by navigating the tabs on the left hand side.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.