1moment().format('MMMM Do YYYY, h:mm:ss a'); // April 14th 2021, 5:38:08 pm
2moment().format('dddd'); // Wednesday
3moment().format("MMM Do YY"); // Apr 14th 21
4moment().format('YYYY [escaped] YYYY'); // 2021 escaped 2021
5moment().format(); // 2021-04-14T17:38:08+06:00
1npm install moment --save #npm
2
3const moment = require('moment'); //require
4
5moment().format('MMMM Do YYYY, h:mm:ss a'); // February 13th 2021, 1:49:03 am
6moment().format('dddd'); // Saturday
7moment().format("MMM Do YY"); // Feb 13th 21
8moment().format('YYYY [escaped] YYYY'); // 2021 escaped 2021
9moment().format(); // 2021-02-13T01:49:29+01:00
10moment("20111031", "YYYYMMDD").fromNow(); // 9 years ago
11moment("20120620", "YYYYMMDD").fromNow(); // 9 years ago
12moment().startOf('day').fromNow(); // 2 hours ago
13moment().endOf('day').fromNow(); // in a day
14moment().startOf('hour').fromNow(); // an hour ago
15moment().subtract(10, 'days').calendar(); // 02/03/2021
16moment().subtract(6, 'days').calendar(); // Last Sunday at 1:50 AM
17moment().subtract(3, 'days').calendar(); // Last Wednesday at 1:50 AM
18moment().subtract(1, 'days').calendar(); // Yesterday at 1:50 AM
19moment().calendar(); // Today at 1:50 AM
20moment().add(1, 'days').calendar(); // Tomorrow at 1:50 AM
21moment().add(3, 'days').calendar(); // Tuesday at 1:50 AM
22moment().add(10, 'days').calendar(); // 02/23/2021
23moment.locale(); // en
24moment().format('LT'); // 1:50 AM
25moment().format('LTS'); // 1:50:49 AM
26moment().format('L'); // 02/13/2021
27moment().format('l'); // 2/13/2021
28moment().format('LL'); // February 13, 2021
29moment().format('ll'); // Feb 13, 2021
30moment().format('LLL'); // February 13, 2021 1:50 AM
31moment().format('lll'); // Feb 13, 2021 1:50 AM
32moment().format('LLLL'); // Saturday, February 13, 2021 1:50 AM
33moment().format('llll'); // Sat, Feb 13, 2021 1:51 AM
1var travelTime = moment().add(642, 'seconds').format('hh:mm A');// it will add 642 seconds in the current time and will give time in 03:35 PM format
2
3var travelTime = moment().add(11, 'minutes').format('hh:mm A');// it will add 11 mins in the current time and will give time in 03:35 PM format; can use m or minutes
4
5var travelTime = moment().add(2, 'hours').format('hh:mm A');// it will add 2 hours in the current time and will give time in 03:35 PM format
1moment().format('MMMM Do YYYY, h:mm:ss a'); // December 4th 2020, 1:04:29 pm
2moment().format('dddd'); // Friday
3moment().format("MMM Do YY"); // Dec 4th 20
4moment().format('YYYY [escaped] YYYY'); // 2020 escaped 2020
5moment().format(); // 2020-12-04T13:04:29-05:00
1moment("20111031", "YYYYMMDD").fromNow(); // 9 years ago
2moment("20120620", "YYYYMMDD").fromNow(); // 8 years ago
3moment().startOf('day').fromNow(); // 13 hours ago
4moment().endOf('day').fromNow(); // in 11 hours
5moment().startOf('hour').fromNow(); // 4 minutes ago