0

I have two applications with different time zones.

Application 1: -Duser.timezone=Australia/Darwin

Application 2: -Duser.timeZone=Asia/Kolkata

Application 1 inserts TimeStamp based on Zone1 and Application2 inserts TimeStamp based on Zone2.

While fetching data from Application1, Zone conversion is not done. Instead it displays the same result.

Values inserted to DB:

2019-02-19 15:39:40 - Application1

2019-02-19 11:40:09 - Application2

Output when fetched from Application 1/ Application2

Time Stamp from DB: 2019-02-19 15:39:40.0

Time Stamp from DB: 2019-02-19 11:40:09.0

For Example , if data is read from Application 1, time Stamp should be displayed according to Austria/Darwin.

How to achieve this?

Here is the code snippet.

String selectSQL = "select createdtime from TZ_TEST6";
PreparedStatement ps = conn.prepareStatement(selectSQL);
ResultSet rs = ps.executeQuery(selectSQL );



while (rs.next())
    {
         Timestamp timestamp = rs.getTimestamp(1);
         System.out.println("Time Stamp  from DB: " +timestamp);
    }
Diya
  • 127
  • 1
  • 9
  • “MySQL converts `TIMESTAMP` values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval.” ([Docs](https://dev.mysql.com/doc/refman/5.5/en/datetime.html)) So this is the datatype you should use. Then store and retrieve `OffsetDateTime` to and from the database (not the poorly designed and long outdated `Timestamp`). – Ole V.V. Feb 19 '19 at 07:49
  • While retrieving data from Application2(Australia/Darwin), all the time stamps persisted in the DB has to be converted to the current time zone((Australia/Darwin). This is my understanding. But, my output shows otherwise. – Diya Feb 19 '19 at 07:57
  • There are a number of seemingly similar questions, for example [MySQL Time zone confusion](https://stackoverflow.com/questions/13071287/mysql-time-zone-confusion). Search for more. – Ole V.V. Feb 19 '19 at 12:31
  • Are you saving timezone info along with timestamp in the DB? – muasif80 Feb 20 '19 at 22:23

0 Answers0