MatBlazor
MatBlazor copied to clipboard
MatDatePicker subtracts 1 day from selected date
Description This issue have been talked about before, but from what Im seeing the bug is still here. Its very simple: Add MatDatePicker component and select a date. The output is selected date - 1 day. Using the ToLocale does not seem to fix the issue. On my local machine it works fine but when I upload to Azure the bug starts to show. The number you select in the datepicker should reflect the output.
Steps to reproduce the behavior:
- Create a new project and install the MatBlazor package.
- Add MatDatePicker to a page.
- Select a date
In this example I select the 23rd. The code was uploaded to an Azure web app so this example is not from my locale machine.
Screenshots
Can confirm too. Happens locally and on my server. I also tried overriding the Format
property on MatDatePicker
in multiple ways and always yields date -1.
I've tried stepping through some of the Flatpickr and matblazor JS and it looks like the correct date is being passed there; the pop-up shows the correct date and the text field is minus 1 day.
I am also getting this issue when selecting a date a -1 value is set on the bound field
For me it's always setting time to 10 PM (I have time picker completely disabled too, only date) and thus it also results in setting -1 day than selected. The date is set to UTC.
However in my case calling date.ToLocalTime()
sets the time back to 00:00:00 (from 10:00:00 PM) so it kind of works around the issue. But definitely needs a long term fix ASAP
And there are two similar cases:
- at MatBlazor site DatePicker yields selected date -1 and shows it with that new value;
- in my proj DatePicker does things equal, but shows correct date (and sets yieded date to binded value)
Ладно, мой английский заставляет страдать, так что на всякий случай пишу ещё и так. Наблюдаю два схожих случая:
- на Вашем сайте MatBlazor DataPicker устанавливает значение со сдвигом на -1 и отображает его уже сдвинутым;
- в моём проекте он всё так же устанавливает забинженое значение со сдвигом на -1, но отображает при этом корректную дату
This worked for me: ExampleDate = ExampleDate.Value.AddDays(0).ToLocalTime();
for me in the datepicker(ui) it shows 2nd Feb but when I am fetching the value from formControl it subtracts 1 from days.
The display and the fetched values should be same.
In my case worked the following:
- yourDate.toLocaleDateString() --> DD/MM/YYYY
- yourDate.toLocaleString() --> DD/MM/YYYY HH:mm:ss