The ServerTimezoneOffset value of the SfDateTimePicker seems to have no effect
Hi There,
The date returned from the SfDateTimePicker is the same for these two elements
<SfDateTimePicker TValue="DateTime" @bind-Value="@DTPickerDate1" Format="@SfDatePickerFormatString" />
<SfDateTimePicker TValue="DateTime" @bind-Value="@DTPickerDate2" Format="@SfDatePickerFormatString" ServerTimezoneOffset="-6" />When I select the same date time in both pickers, I expect DTPickerDate2 to be 6 hours behind DTPickerDate1 but they are the same?
Thanks
Joseph
SIGN IN To post a reply.
5 Replies
1 reply marked as answer
SN
Sevvandhi Nagulan
Syncfusion Team
October 15, 2020 01:09 PM UTC
Hi Joseph,
Greetings from Syncfusion support.
We checked the reported requirement. If you select the same date and time in both components, then we have updated the time of the second DateTimePicker 6 hours behind the selected time. Refer to the code below,
|
<SfDateTimePicker TValue="DateTime?" @bind-Value="@DTPickerDate1">
<DateTimePickerEvents TValue="DateTime?" ValueChange="OnDateChange1"></DateTimePickerEvents>
</SfDateTimePicker>
<SfDateTimePicker TValue="DateTime?" @bind-Value="@DTPickerDate2">
<DateTimePickerEvents TValue="DateTime?" ValueChange="OnDateChange2"></DateTimePickerEvents>
</SfDateTimePicker>
@code {
public DateTime? DTPickerDate1 { get; set; }
public DateTime? DTPickerDate2 { get; set; }
public void OnDateChange1(ChangedEventArgs<DateTime?> args)
{
if (DTPickerDate1 == DTPickerDate2)
{
DTPickerDate2 = DTPickerDate2.Value.AddHours(-6);
}
}
public void OnDateChange2(ChangedEventArgs<DateTime?> args)
{
if(DTPickerDate1 == DTPickerDate2)
{
DTPickerDate2 = DTPickerDate2.Value.AddHours(-6);
}
}
}
|
Please find the sample below,
Please check the above sample and get back to us if you need further assistance.
Regards,
Sevvandhi N
Marked as answer
JT
Joseph Tan
October 15, 2020 06:37 PM UTC
That looks like a workaround.
Does ServerTimezoneOffset not work?
SN
Sevvandhi Nagulan
Syncfusion Team
October 16, 2020 08:16 AM UTC
Hi Joseph,
We would like to inform you that, we implemented the DateTimePicker control completely in server side. Now, there is no interaction between the client and server in the Blazor DateTimePicker. Basically, whenever a client and server interaction occurs, date changes will occur as the date is passed from client to server. We given the ServerTimezoneOffset property to avoid problems of this kind. But the problem is no longer going to occur in Blazor DateTimePicker. Therefore, the ServerTimezoneOffset property will not work here.
Regards,
Sevvandhi N
JT
Joseph Tan
October 16, 2020 08:44 AM UTC
Well, what I was trying to do is this :
The DateTimePicker control always displays the time in the browser's timezone, but stores the time in the server's timezone (TimezoneInfo.Local). If I want to store dates in UTC, I have to manually convert the date that is bound to the Datetimepicker : DTPickerDate1.ToUniversalTime();
What I was hoping to do is set ServerTimezoneOffset (e.g. '-6') which is the offset of TimezoneInfo.Local to UTC.
<SfDateTimePicker TValue="DateTime" @bind-Value="@DTPickerDate1" Format="@SfDatePickerFormatString" ServerTimezoneOffset="-6" />
This would cause the Datepicker display the time in the browser's timezone, but store the time in UTC.
From your documentation, it looked like ServerTimezoneOffset would do exactly that, so its disappointing to see that it is no longer supported.
SN
Sevvandhi Nagulan
Syncfusion Team
October 21, 2020 05:06 PM UTC
Hi Joseph,
Sorry for the delay.
We can get the UTC time by changing the TValue to DateTimeOffset. Please refer to the code below,
|
<SfDateTimePicker TValue="DateTimeOffset?" @bind-Value="DTPickerDate1"></SfDateTimePicker>
@code {
public DateTimeOffset? DTPickerDate1 { get; set; }
|
Screenshot:
Please find the sample below,
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DateTimePicker-1932233145
Please check the above suggestion and get back to us if you need further assistance.
Regards,
Sevvandhi N
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
- Marked answer
-
JT Joseph Tan
- Oct 4, 2020 09:09 PM UTC
- Oct 21, 2020 05:06 PM UTC