Material date pickers will always put the current hour seconds of your browser timezone, I have a lot of problems with that but you can always do
import React from "react";
export default function YourComponent() {
const [firstDate, setFirstDate] = React.useState(null)
const handleFirstDateChange = (date) => {
const newDate = date;
// Check if date is present, user can leave it as an empty field
if (date) {
//Set's the given date to UTC midnight (start of the day)
newDate.setUTCHours(0,0,0,0);
}
// Set the date to your local state or where you are storing it
setFirstDate(newDate)
}
return (
<KeyboardDatePicker
className="search-element"
disableToolbar
variant="inline"
format="dd/MM/yyyy"
id="date-picker-inline"
label="пошук в?д"
value={firstDate}
onChange={handleFirstDateChange}
KeyboardButtonProps={{
'aria-label': 'set first date',
}}
/>
)
}
This will make the date to use the UTC start of the day, you can also use setHours but that one will use your browser timezone, which can be different depending on the user location.
I would also suggest to use Luxon library and luxon utils instead of date-fns if your requirements need a specific timezone(this is what I ended up doing).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…