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.
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.
// 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.
This page will automatically be redirected to the sign-in page in 10 seconds.