mui/material-ui-pickers

Facing issue with KeyboardDatePicker

eswarant opened this issue · 6 comments

Refer below screenshot & this URl https://material-ui-pickers.dev/guides/form-integration.
I am typing 21/10/2020 but the result is 2020-10-20T18:30:00.000Z so its displaying one day off
image

That is expected. Datepicker chooses time the user LOCAL TIME. And when you convert the date to UTC (Z in the end of iso string means UTC) it will be changed. But the point of time is right - the start of day in user's time zone.

what needs to be done if I want the same as typed which means 2020-10-21

It is still the 2020-10-21. But in your local time zone.

i understand 2020-10-20 would be 2020-10-21 in my time zone. how to display as 2020-10-21 instead 2020-10-20 in my UI

One more clarification: We are considering local time when selecting date from picker but not when we are typing date manually . is there any specific reason?

One more time: this is local time. It is only the mechanism of displaying Date objects in the browser. Check this sandbox https://codesandbox.io/s/immutable-hill-ijylk?file=/src/index.js

When you work with date-fns and Date objects you work in local timezone, but when serializing date it converts to the UTC