let end: Date = new Date();
let h: string = "13";
let m: string = "20";
moment(end).set({ hour: parseInt(h, 10), minute: parseInt(m, 10) });
I am trying to set time on an existing date. however the above doe is not setting the time in the date. The time always comes as ...00:00:...
Any idea?
Thanks,
let end: Date = new Date();
let h: string = "13";
let m: string = "20";
moment(end).set({ hour: parseInt(h, 10), minute: parseInt(m, 10) });
I am trying to set time on an existing date. however the above doe is not setting the time in the date. The time always comes as ...00:00:...
Any idea?
Thanks,
Share Improve this question asked Dec 3, 2015 at 15:43 activebizactivebiz 6,2309 gold badges43 silver badges65 bronze badges 1 |1 Answer
Reset to default 16You have to convert your moment to a Date
, and assign that Date
object to your end
variable:
end = moment(end)
.set({ hour: parseInt(h, 10), minute: parseInt(m, 10) })
.toDate();
moment(end)
makes a new Moment object with a new Date buried inside it. Changes to that won't affect the original Date instance. – Pointy Commented Dec 3, 2015 at 15:44