We are getting “org.postgresql.util.PSQLException: ERROR: invalid input syntax for type timestamp: “Wed Jun 26 23:27:35 TRT 2024″” as an exception when our application tries to insert the given date to a timestamp (PostgreSQL) column. I assume it is because of the timezone being TRT instead of EET. This only occurs in one of our linux servers and not on any others which indicates that it is an environmental issue but I couldn’t locate what might be causing it. We are using new Date(System.currentTimeMillis()) to get the date.
I have tried checking the time zone of the servers by using date and datectl but they are identical with both of them being in the GMT+3 timezone. I also created a small application to check JVM and user time zone. Here is the code:
System.out.println("JVM Time Zone : " + java.util.TimeZone.getDefault().getID());
System.out.println("User Time Zone : " + System.getProperty("user.timezone"));
System.out.println("Milliseconds : " + System.currentTimeMillis());
Date date = new Date(System.currentTimeMillis());
System.out.println(date.toString());
When I ran this application it gave the same result in both of the servers (disregarding the difference in miliseconds time that it takes for me to run the application). I have also used the command locale to check if there is any difference in the locale of the servers but it was the same. Another thing I checked was the Java versions as apparently the time zone changes between java 1.8 and java 17 for Turkey. While 17 gave TRT, 1.8 gave EET as the time zone when I ran it on my local computer. So I checked the versions of java between servers but it was the same. I also checked to see if there is any parameters passed when the Jboss server we are using is starting. Here is the parameters when I look at the processes:
java -D[Standalone] -server -XX:+UseCompressedOops -verbose:gc -Xloggc:/opt/jboss-eap-6.4/standalone1/log/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading -Xms2048m -Xmx2048m -XX:MaxPermSize=512m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Djboss.modules.policy-permissions=true -Dorg.jboss.boot.log.file=/opt/jboss-eap-6.4/standalone1/log/server.log -Dlogging.configuration=file:/opt/jboss-eap-6.4/standalone1/configuration/logging.properties -jar /opt/jboss-eap-6.4/jboss-modules.jar -mp /opt/jboss-eap-6.4/modules -jaxpmodule javax.xml.jaxp-provider org.jboss.as.standalone -Djboss.home.dir=/opt/jboss-eap-6.4 -Djboss.server.base.dir=/opt/jboss-eap-6.4/standalone1 -Djboss.server.base.dir=/opt/jboss-eap-6.4/standalone1 -Djboss.bind.address=<IP> -Djboss.bind.address.management=<IP> --server-config=standalone.xml
I checked this post but it differs from this question since in this problem it shows the same result when timedatectl is used. We have multiple applications that uses the new Date(System.currentTimeMillis()) to get the current date so if there is a solution that does not involve changing it I would appreciate it.