I am trying to set a default value in my material ui time picker, The time value am trying to set as default is formatted this way - 9:00:00 AM
This is the TimePicker Below
<LocalizationProvider dateAdapter={AdapterDayjs}>
<TimePicker
value={valueFrom}
onChange={(newValue) => {
onChange(newValue, nameFrom);
console.log('Time Value: ', newValue.$d.toLocaleTimeString('en-US')); // 9:00:00 AM
}}
renderInput={(params) => <TextField
size="small"
variant="outlined"
required={valueCheckbox1}
{...params} />}
disabled={!valueCheckbox1 || valueCheckbox2 ? true : false}
style={{color: 'white'}}
/>
</LocalizationProvider>
How can I set a default time that comes in this format 9:00:00 AM on the time picker above
CodePudding user response:
You pass it as a Date
so if you put something like this in your code, it should work. Just change day to whatever you need to.
const valueFrom = new Date()
valueFrom.setHours(9)
valueFrom.setMinutes(0)