moment set date code example
Example 1: moment set time
const date = "2017-03-13";
const time = "18:00";
const timeAndDate = moment(date + ' ' + time);
console.log(timeAndDate);
Example 2: moment date add
var new_date = moment(startdate, "DD-MM-YYYY").add(5, 'days');
Example 3: moment.js format
moment().format('MMMM Do YYYY, h:mm:ss a'); // December 4th 2020, 1:04:29 pm
moment().format('dddd'); // Friday
moment().format("MMM Do YY"); // Dec 4th 20
moment().format('YYYY [escaped] YYYY'); // 2020 escaped 2020
moment().format(); // 2020-12-04T13:04:29-05:00
Example 4: moment.set
moment().set('year', 2013);
moment().set('month', 3); // April
moment().set('date', 1);
moment().set('hour', 13);
moment().set('minute', 20);
moment().set('second', 30);
moment().set('millisecond', 123);
moment().set({'year': 2013, 'month': 3});