• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

How to handle Timezones issues in Different systems.

Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

My application runs in Java and my Database is Mysql.

The application handles various sports results and scores across the world. My application converts everything to EST and stores in DB and while displaying converts the times to local timezones and shows it.

Till now I have a virtual machine where I set the timezone to EST and both my Java and Database running there.
And all my time calculations in Java used EST as the system zone.

I see the laptop timezone also to EST so that I can run the test cases and import the database from server for testing.

But now I want to move the infra.. and that new server does not support the EST timezone , both Java and MysQL servers. So I have to change my code to UDT also change the entire database entries to EDT.

I know I am doing something wrong.
So is there a way to write the code and store the data, where I can store the data and deploy the application in any server irrespective the servers timezone setup ?

Lets the I have the data and Java application ..
                    1. I should be able to deploy the application in IST (India Standard Time) laptop and connect to DB server which is running on UDT.
                   2. I should be able to dump the data into my laptop (again in IST) and run the application without any issues.
                   3. I should be able to deploy the application in a server which is running UDT and access the db which is running in UDT server without any issues..

Can someone please help suggesting the best way to handle this..

Saloon Keeper
Posts: 27816
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's see if I can help.

Actual Java time objects are expected to be in UTC time, always. You can select a local timezone for input/output, but you've made an error if you didn't convert using the standard date/time conversion services with timezone. This is why the (M, D, Y) java.lang.Date constructor has been deprecated for so many years. In EST/EDT. the day is out of sync with the UTC day for 4-5 hours.

Databases typically support several different date and time formats, including date without time, time without date and time/date with or without timezone. For best international support, you should choose the time/date format that you can assume holds UTC times.

So if you have existing data and you managed to store it in EST/EDT then you may need to convert it - and possibly adjust for whether the time in question is Standard or Daylight (UTC has no DST).

Having done that, you should vet your code to ensure that it is making properly allowances for normalisation of the timezone.

As far as dumping a database, the SQL convention is that the time/date would either be UTC or timestamp with time/zone information. It's likely that you'll want to write a custom dump program to format things more according to your liking.
pie. tiny ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic