Click here to Skip to main content
13,090,930 members (47,367 online)
Rate this:
Please Sign up or sign in to 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.

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

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 26-Feb-13 19:51pm
Updated 26-Feb-13 21:07pm
By reading documentation. How can it possibly be a problem? What did you try so far?
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100