)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

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

Platform: jQuery |
Control: ejDateTimePicker |
Published Date: January 3, 2017 |
Last Revised Date: May 7, 2019

Why DateTimePicker changing time when application hosted in different Time zone

EJ DateTimepicker 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.

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon