momentjs.com code example

Example 1: moment format

moment().format('MMMM Do YYYY, h:mm:ss a'); // September 30th 2020, 2:48:17 pm
moment().format('dddd');                    // Wednesday
moment().format("MMM Do YY");               // Sep 30th 20
moment().format('YYYY [escaped] YYYY');     // 2020 escaped 2020
moment().format();                          // 2020-09-30T14:48:17+02:00

Example 2: momentjs

npm install moment --save   # npm
yarn add moment             # Yarn
moment.locale();         // en
moment().format('LT');   // 8:49 AM
moment().format('LTS');  // 8:49:26 AM
moment().format('L');    // 10/13/2020
moment().format('l');    // 10/13/2020
moment().format('LL');   // October 13, 2020
moment().format('ll');   // Oct 13, 2020
moment().format('LLL');  // October 13, 2020 8:49 AM
moment().format('lll');  // Oct 13, 2020 8:49 AM
moment().format('LLLL'); // Tuesday, October 13, 2020 8:49 AM
moment().format('llll'); // Tue, Oct 13, 2020 8:49 AM

Example 3: moment js

moment().format('MMMM Do YYYY, h:mm:ss'); // March 24th 2021, 4:03:03 pm
moment().format('dddd');                    // Wednesday
moment().format("MMM Do YY");               // Mar 24th 21
moment().format('YYYY [escaped] YYYY');     // 2021 escaped 2021
moment().format();                          // 2021-03-24T16:03:03-03:00

Example 4: moment

moment("20111031", "YYYYMMDD").fromNow(); // há 9 anos
moment("20120620", "YYYYMMDD").fromNow(); // há 8 anos
moment().startOf('day').fromNow();        // há 13 horas
moment().endOf('day').fromNow();          // em 11 horas
moment().startOf('hour').fromNow();       // há 10 minutos

Example 5: moment js

moment().format('MMMM Do YYYY, h:mm:ss'); // March 24th 2021, 4:02:53 pm
moment().format('dddd');                    // Wednesday
moment().format("MMM Do YY");               // Mar 24th 21
moment().format('YYYY [escaped] YYYY');     // 2021 escaped 2021
moment().format();                          // 2021-03-24T16:02:53-03:00

Example 6: mimonts js

moment().format('MMMM Do YYYY, h:mm:ss a'); // December 17th 2020, 2:06:38 pm
moment().format('dddd');                    // Thursday
moment().format("MMM Do YY");               // Dec 17th 20
moment().format('YYYY [escaped] YYYY');     // 2020 escaped 2020
moment().format();                          // 2020-12-17T14:06:38+03:00