moment js format days code example

Example 1: moment format date

moment.locale();         // en
moment().format('LT');   // 12:25 PM
moment().format('LTS');  // 12:25:27 PM
moment().format('L');    // 03/26/2021
moment().format('l');    // 3/26/2021
moment().format('LL');   // March 26, 2021
moment().format('ll');   // Mar 26, 2021
moment().format('LLL');  // March 26, 2021 12:25 PM
moment().format('lll');  // Mar 26, 2021 12:25 PM
moment().format('LLLL'); // Friday, March 26, 2021 12:25 PM
moment().format('llll'); // Fri, Mar 26, 2021 12:25 PM

Example 2: moment add seconds

var 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

var 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 

var 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

Example 3: moment format date

moment().format('MMMM Do YYYY, h:mm:ss a'); // March 26th 2021, 12:25:33 pm
moment().format('dddd');                    // Friday
moment().format("MMM Do YY");               // Mar 26th 21
moment().format('YYYY [escaped] YYYY');     // 2021 escaped 2021
moment().format();                          // 2021-03-26T12:25:33-04:00

Example 4: moment to javascript date

let now = moment()
let now = now.toDate()