Last post May 18, 2018 06:38 AM by Nan Yu
May 17, 2018 10:40 AM|mohsin.afridi91|LINK
I am Working on MVC Application,where my users are from Different TimeZones.
Now I have saved CreatedDate,UpdatedDate etc in UTC,like in C#
Now I want to populate or show DateTime in User Locations or Browser Location TimeZone as well as in their DateTime Format.
As I have many textboxes to show datetime and many labels.
Is there any generic way to handle this.
May 17, 2018 01:29 PM|bruce (sqlwork.com)|LINK
May 18, 2018 06:38 AM|Nan Yu|LINK
As @bruce said , you have to convert these date-times that are in UTC timezone to the clients timezone and for that you have to know the timezone of the client. One way is use
getTimezoneOffset() that returns the time difference between client and UTC timezones in minutes. By knowing this value when the client send the request we can adjust the UTC date-times into client date-time . you can
store the timezone offset in the cookie and since the cookies are sent to server for every request; from the server side we have to retrieve the value from the cookie and store in session. Whenever we are going to display the date-time to the user we have
to convert the UTC date-time into client time based on the offset value stored in the session. Please refer to below link for detail explanation and code samples :