Considering using Moment in your project? Moment.js 2.29.4 Parse, validate, manipulate, and display dates and times in JavaScript.
Moment.js has been successfully used in millions of projects, and we are happy to have contributed to making date and time better on the web. As of September 2020, Moment gets over 12 million downloads per week! However, Moment was built for the previous era of the JavaScript ecosystem. The modern web looks much different these days. Moment has evolved somewhat over the years, but it has essentially the same design as it did when it was created in 2011. Given how many projects depend on it, we choose to prioritize stability over new features.
Format Datesmoment().format('MMMM Do YYYY, h:mm:ss a'); // July 22nd 2022, 11:38:49 am
moment().format('dddd'); // Friday
moment().format("MMM Do YY"); // Jul 22nd 22
moment().format('YYYY [escaped] YYYY'); // 2022 escaped 2022
moment().format(); // 2022-07-22T11:38:49+10:00
Relative Timemoment("20111031", "YYYYMMDD").fromNow(); // 11 years ago
moment("20120620", "YYYYMMDD").fromNow(); // 10 years ago
moment().startOf('day').fromNow(); // 12 hours ago
moment().endOf('day').fromNow(); // in 12 hours
moment().startOf('hour').fromNow(); // 39 minutes ago
Calendar Timemoment().subtract(10, 'days').calendar(); // 07/12/2022
moment().subtract(6, 'days').calendar(); // Last Saturday at 11:38 AM
moment().subtract(3, 'days').calendar(); // Last Tuesday at 11:38 AM
moment().subtract(1, 'days').calendar(); // Yesterday at 11:38 AM
moment().calendar(); // Today at 11:38 AM
moment().add(1, 'days').calendar(); // Tomorrow at 11:38 AM
moment().add(3, 'days').calendar(); // Monday at 11:38 AM
moment().add(10, 'days').calendar(); // 08/01/2022
Multiple Locale Supportmoment.locale(); // en
moment().format('LT'); // 11:38 AM
moment().format('LTS'); // 11:38:49 AM
moment().format('L'); // 07/22/2022
moment().format('l'); // 7/22/2022
moment().format('LL'); // July 22, 2022
moment().format('ll'); // Jul 22, 2022
moment().format('LLL'); // July 22, 2022 11:38 AM
moment().format('lll'); // Jul 22, 2022 11:38 AM
moment().format('LLLL'); // Friday, July 22, 2022 11:38 AM
moment().format('llll');
For more details and recommendations, please see Project Status in the docs.
https://momentjs.com/