How to set Date of an existing moment.js object

It may be a little late, but you can transform your new date to an object (newDate.toObject()) and pass it to the set method of your previous moment object:

var m = moment(); // Initial moment object

// Create the new date
var myDate = new Date();
var newDate = moment(myDate);

// Inject it into the initial moment object
m.set(newDate.toObject());

Leave a Comment