Bug #98468 Timestamp retrieved from DATETIME column have to be corrected with 'GMT-6:00'
Description:
On Docker for Windows, image mysql:latest(8.0.19) and Connector / J (mysql:mysql-connector-java:8.0.19), retrieved a java.sql.Timestamp from a DATETIME typed column returns incorrect result.
Correct result from mysql CLI:
+---------------------+
| dt |
+---------------------+
| 2020-02-03 21:00:00 |
+---------------------+
1 row in set (0.00 sec)
Result resulted from the following code:
2020-02-04 11:00:00.0
How to repeat:
On described environment (TZ environment variable of Docker image has been set to my local timezone), run following code:
```kotlin
Class.forName("com.mysql.cj.jdbc.Driver")
val conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/database", "test", "1234")
val stat = conn.createStatement()
stat.execute("create table test (dt timestamp null)")
stat.execute("insert into test values ('2020-02-03 21:00:00')")
stat.executeQuery("select * from test")
.let {
it.next()
println(it.getTimestamp("dt"))
}
```
you'll get 2020-02-04 11:00:00.0 instead of 2020-02-03 21:00:00.
note that the wrong result is neither in my current timezone, nor UTC. you have to corrected the result by run following code beforehand:
```
TimeZone.setDefault(TimeZone.getTimeZone("GMT-6:00"))
```
this affects all Local* as well.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.051 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: On Docker for Windows, image mysql:latest(8.0.19) and Connector / J (mysql:mysql-connector-java:8.0.19), retrieved a java.sql.Timestamp from a DATETIME typed column returns incorrect result. Correct result from mysql CLI: +---------------------+ | dt | +---------------------+ | 2020-02-03 21:00:00 | +---------------------+ 1 row in set (0.00 sec) Result resulted from the following code: 2020-02-04 11:00:00.0 How to repeat: On described environment (TZ environment variable of Docker image has been set to my local timezone), run following code: ```kotlin Class.forName("com.mysql.cj.jdbc.Driver") val conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/database", "test", "1234") val stat = conn.createStatement() stat.execute("create table test (dt timestamp null)") stat.execute("insert into test values ('2020-02-03 21:00:00')") stat.executeQuery("select * from test") .let { it.next() println(it.getTimestamp("dt")) } ``` you'll get 2020-02-04 11:00:00.0 instead of 2020-02-03 21:00:00. note that the wrong result is neither in my current timezone, nor UTC. you have to corrected the result by run following code beforehand: ``` TimeZone.setDefault(TimeZone.getTimeZone("GMT-6:00")) ``` this affects all Local* as well.