Skip to content
Advertisement

Strange date error between Development and Production environment

I have a strange date error that I can’t solve for days and ask for your help.

I have developed in Java/Spring/Vaadin/Hibernate an app that creates a sport training every day by a user. The problem is that the training date is not displayed correctly in browser. For example, I create now a new training:

training.setTrainingdate(LocalDate.now());

On localhost shows right but online from Amazon AWS Tomcat shows it wrong date (one day before). The MySql database is common for both cases = Amazon RDS Mysql. My Time zone is UTC +1 (Europe/Vienna)

2020-02-17

but in the browser when I get the trainig from aws is show

2020-02-16

What I’ve already checked:

– On AWS-RDS-MySQL Server:

SELECT now();

2020-02-17 12:55:50

and

SELECT * FROM `mydatabase`.training;

2020-02-17

– Elastic Beanstalk on SSH:

date

Mon Feb 17 11:55:50 UTC 2020

  • Log files
  • /var/log/tomcat8/catalina.out
  • /var/log/tomcat8/httpd/access_log
  • /var/log/tomcat8/httpd/error_log

2020-02-17 11:55:50.985

No matter what time I try the difference stay one day.

Different devices and different browser same problem.

Do you have an Ideea what can be? Thank you very much!

EDIT:

TimeZone.getDefault())

On Production Server:

sun.util.calendar.ZoneInfo[id=”Universal”,offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]

On localhost:

sun.util.calendar.ZoneInfo[id=”Europe/Berlin”,offset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]

Advertisement

Answer

RESOLVED

Solution:

  • I add a version to maven mysql-connector-java dependency:

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.48</version>
    </dependency>
    

I add to spring applications.properties:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

and add/change in the tail of spring.datasource.url to:

?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false

PS Many thanks to all who try to help! Specially thanks to @Leif Åstrand and @PeMa

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement