Wednesday, June 22, 2011

Time Zone conversion

Many times I encoutered this doubt, how to handle the time zone difference in our applications. What if the user changes to a different time zone, while our application is time-zone dependent.

Here is the simple understanding with an example. Implementation of an application which store the previously logged in time. Say, now the time is IST 04:00 PM (GMT +5.30). The application will store the current time in the preferences and inform the user about the last logged in time, irrespective of the time-zone.

Step 1: Store the current time always in GMT format. When the current time is stored in specific time zone format, then when the time zone changes, we would not be able to retrieve the appropriate time.
Step 2: Convert them to GMT time to locale time whenever required.
Step 3: Ensure to use proper FORMAT across all the locations in the applications


Refer the following code snippet to understand the conversion process. 


No comments:

Post a Comment

Thanks for visiting this blog. Please write to me if any doubt. Let me help you if I can.