Articles in this section
Category / Section

Datetime values differs from the actual time selected when the client is located in different time zone.

3 mins read

JavaScript Timepicker control is used to get the Date and Time values from the user with a specific format. 

For websites hosted in different Time zone, the time being selected in different time zone will differ with respect to the local time.

So, in order to overcome this Time zone discrepancy, the date time value being selected on client end will be converted to its equivalent Coordinated Universal Time (UTC) on server end.

Say, for example if the date time selected is 12/22/2016 7:30 AM, where the Time Zone is 5.30 hours ahead of UTC, then at the server end, the time will be converted to its equivalent UTC i.e., 12/22/2016 2:00 AM.

DateTimePicker

This conversion is done in order to overcome the time zone discrepancies across the world.

Now, to receive the equivalent local date and time as selected by the user in different time zone (say, 1.30 hours behind the UTC), it can be done by adjusting the value with local Time Zone offset as given below.

HTML

 
        // local time zone offset as TimeSpan object 
        var offsetTime = TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow).Ticks;
 
        // convert time zone offset to minutes
        var localtime_minutes = TimeSpan.FromTicks(offsetTime).TotalMinutes;
 
        // add the offsetTime to the datetime recieved as UTC
        ViewData["date"] = data.date.AddMinutes(localtime_minutes);
 

 

With this conversion, you can get the date and time selected by the user in a different time zone.

So, the local time would be 12/22/2016 0:30 AM at the time when the user has selected 12/22/2016 7:30 AM.

Conclusion

I hope you enjoyed learning about how datetime values differs from the actual time selected when the client is located in different time zone.

You can refer to our JavaScript TimePicker feature tour page to know about its other groundbreaking feature representations. You can also explore our JavaScript TimePicker documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied