Click here to Skip to main content
15,896,402 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Guys,

I am stumble in the scenario where i need to convert UTC DateTime stored in the database to local time once the user retrieved the data and rendered in their respective browsers.

My current solution is: to get the timezone of the current user and store in session and use that to convert the utc to local time.

current problem: the timezone of the current user might vary for daylight saving. and for scenario where the timezone of the current user is in daylight saving mode but the date to convert is in regular time.

scenario:
1. user saved data on regular time
2. during daylight saving user open the app and retrieved data
3. when converting the datetime the timezone that will be use is daylight saving

Question:
1. What is the best approach to handle datetime conversion from utc to local time where daylight saving is also considered?
2. Is there a way to determine if the utc is in daylight or ordinary time?
Posted
Updated 26-Feb-13 21:07pm
v3
Comments
Sergey Alexandrovich Kryukov 27-Feb-13 2:14am    
By reading documentation. How can it possibly be a problem? What did you try so far?
—SA
Jephunneh Malazarte 27-Feb-13 2:21am    
because the data that was saved was in ordinary time (GMT-5). Now the locale timezone of the user is in day light saving time (GMT-4). so when i use that to convert the time the result will be 1 hr diff.

1 solution

 
Share this answer
 
Comments
Jephunneh Malazarte 7-Mar-13 21:18pm    
thanks, i'll accept your solution because this is indeed part of the solution but not the exact one though. The problem is a bit complicated than a mere conversion of UTC to Local DateTime.
Richard MacCutchan 8-Mar-13 3:49am    
But it is the exact solution. Whenever you are storing datetime values in a database or other permanent storage, you must always store the UTC value of that time. Then at some later time when you wish to display it, you convert it back to its local time value. In that way it will always be correct and adjusted for daylight savings: that is assuming you use the correct conversion routines.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900