Working scenario:
Service-A : with Java 8 , Spring boot 2.7.x
- Setting the ZoneddateTime (“America/New_York”) in java object and adding
it in RabbitMQ queue.
Service-B : with Java 8 , Spring boot 2.7.9
- Receives the ZoneddateTime from Queue and persisting it in MySql DB.
- ZoneddateTime is persisted in EST/EDT format as expected.
Mysql DB:
- Result of the query (SELECT @@system_time_zone;) is EDT.
- data type column in MySQL store the ZoneddateTime is – datetime
Issue:
After upgrading the Service-B (service which persist the date time in DB) to Java 17 & Spring boot 3.2.9. ZoneddateTime is getting persisted UTC format (EDT + 4 hrs)
Debugging :
- I tried to convert the time to EDT/EST and then persist in DB. But still its storing it in UTC format only.
final ZonedDateTime inboundTimeEST = inboundTime.withZoneSameInstant("America/New_York"); obj.setRequestTime(inboundTimeEST); obj.setMyJson(XXX().getBytes()); // Json in bytes logsRepository.save(obj);
obj is from our entity class. Data type of the request time is ZonedDateTime. imported these two packages import jakarta.persistence.*;import java.time.ZonedDateTime; in our class
- I downgraded the spring boot version to 2.7.9 with Java 17. the ZoneddateTime is persisted in EST/EDT format as expected. So the issue is not due to the Java upgrade i guess.
Any recommendations or suggestion to fix this issue or to debug it further? I am expecting the datetime should be in EDT/EST format.
10