Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unhandled Rejection (TypeError): formProps.date.getTime is not a function

How can I change hour and minute values to an existing Date variable?
formProps.date: existing Date type variable generated from a date picker that I want to use year value only.
formProps.hour: The hour value that user input separately.
formProps.minute: The minute value that user input separately.

Those three values are to be combined into a new Date variable ‘dateWithTime‘, but it throws an error during copying the date values.

It this a wrong way to copy a Date variable? or is there any better way to make it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const dateWithTime = new Date(formProps.date.getTime());
dateWithTime.setHours(formProps.hour, formProps.minute);

enter image description here

==== edit ====
the log of
console.log(formProps.date.toLocaleString());
console.log(typeof(formProps.date));
enter image description here

>Solution :

I don’t know why your code above doesn’t work but the below code worked for me. Could u try to use:

const dateWithTime = new Date(formProps.date.toLocaleString());

(I know it is not an comprehensive answer but I couldn’t add a comment due to my reputation :/ )

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading