March 2019
Intermediate to advanced
534 pages
14h 52m
English
When you use the datetime-local type of input, it simplifies working with the Date instances. Let's take a look at the onChangeDate() handler:
const onChangeDate = e => { setDatetime(new Date(`${e.target.value}Z`));};
You can pass e.target.value as the argument to a new Date instance, which then becomes the new datetime state value. Finally, let's take a look at the formatDate() function that's used to pass the correct value to the value property of TextField:
const formatDate = date => date .toISOString() .split(':') .slice(0, 2) .join(':');
The reason to use this function is to remove the seconds and milliseconds from the value property. Otherwise, these will show up as values in the input field that the user can then select. ...
Read now
Unlock full access