MatDatePicker bind-value shows incorrect
When I select any date in the MatDatePicker the bind-value variable updating by minus one day and the time is by default 6.30 pm. Example: if we select date as 16th July 2019 and the value is getting the update as of 15th July 2019 18:30:00.
I just ran into this issue myself and it seems that you must convert the date given to you by the date picker to local time. Although oddly you don't have to do the reverse when providing dates to the date picker.
Example:
<MatDatePicker @bind-Value="@MyDate" />
@code { private DateTime _myDate; private DateTime MyDate { get => return _myDate; set { _myDate = value.ToLocalTime(); } } }
@RonPeters is this fixed?
I used Salanford comment but for nullable Date you still have to use .ToLocalTime on the getter ...
public DateTime RedactionDate
{
get => Item.RedactionDate;
set => Item.RedactionDate = value.ToLocalTime();
}
public DateTime? EstimatedStartDate
{
get => Item.EstimatedStartDate.HasValue ? (DateTime?)Item.EstimatedStartDate.Value.ToLocalTime() : null;
set => Item.EstimatedStartDate = value.HasValue ? (DateTime?)value.Value.ToLocalTime() : null;
}
Well this works on my machine but when I send on Azure, it's still failling (for both nullable and not nullable Date)... So my awfull workaround is this
public DateTime RedactionDate
{
get => Item.RedactionDate.AddHours(4);
set => Item.RedactionDate = value.AddHours(4);
}
public DateTime? EstimatedStartDate
{
get => Item.EstimatedStartDate.HasValue ? (DateTime?)Item.EstimatedStartDate.Value.AddHours(4) : null;
set => Item.EstimatedStartDate = value.HasValue ? (DateTime?)value.Value.AddHours(4) : null;
}
btw +4 hours works for France in summer/winter
ouch!!
I am also struggling my head off with the same issue when its deployed to Azure
@sebestyn168 Taking inspiration from your answer and applying it to my own use case: I wrapped the MatDatePicker component to better work for me. see answer here
Glad it helped We shipped a new version on MatBlazor last month, everything's fine except for memory conumption on Blazor Server We need to update our Put logic to avoid serialization error in javascript in order to migrate WASM