Good day,
I create web application service, which would be used across the world.
Therefore I need to store datetime values in UTC and represent them in clocks on the wall time to the end user.
After reading Stack overflow, I understood, that I should:
The problem arose while converting between these values.
As I use JDBC, I have to do the following conversion:
java.sql.Timestamp <-> java.time.ZonedDateTime
My code:
// Get current zonedDateTime
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneOffset.UTC);
// Convert zonedDateTime to java.sql.Timestamp before saving to DB
Timestamp = Timestamp.from(zonedDateTime.toInstant());
// Get zonedDateTime from resultSet
Timestamp timestamp = (Timestamp) resultSet.getObject("created");
ZonedDateTime zonedDateTime =
ZonedDateTime.ofInstant(ts.toInstant(), ZoneOffset.UTC))
When I use:
zonedDateTimeBeforeSave.isEqual(zonedDateTimeAfterSave);
It returns me false (I need to compare them in overridden equal method of my domain model)
Below is print out of both:
zonedDateTimeBeforeSave: 2017-01-24T20:18:17.720Z
zonedDateTimeAfterSave: 2017-01-24T20:18:17Z
Questions:
Thank you
I finally found out what was the problem after reading this post and comments:
http://mysqlnoob.blogspot.com/2016/09/replication-from-mysql-56-to-mariadb-10-fails-with-fractional-seconds.html
The reason was my MariaDB JDBC driver
I had an old 1.1.7 version and parameter "useFractionalSeconds" was set to false.
The solution is rather setting this parameter to true (f.ex by URL)
or update driver. Current latest version is 1.5.7 as for 25.01.2017
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With