moment.js set time on existing date is not setting the time correctly
16,128
You 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();
Author by
daehaai
Updated on July 18, 2022Comments
-
daehaai almost 2 years
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,
-
adolfosrs about 7 yearsYou can go with just
parseInt(h)
. Default radix is 10. -
Estus Flask almost 7 years