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,
js parsing date and time. We can parse a string representation of date and time by passing the date and time format to the moment function. const moment = require('moment'); let day = "03/04/2008"; let parsed = moment(day, "DD/MM/YYYY"); console.
By default, moment objects are created in the local time zone. Local time zone - it's a time zone which is set in a browser or on your node. js server.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With