[jdbc] Incorrect DateTime results when writing numeric data with use_time_zone property
Describe the bug
The DateTime results will -8h when inserting long values using PrepareStatement with use_server_time_zone=false&use_time_zone=Asia/Shanghai. (ClickHouse Server timezone is UTC)
Expected: '1970-01-01 08:00:00.001000000' Actual: '1970-01-01 00:00:00.001000000' (timezone is Asia/Shanghai)
Code example
CREATE TABLE t_test
(
`timestamp` DateTime64(3)
)
ENGINE = Log;
try (
Connection connection = DriverManager.getConnection("jdbc:ch://localhost:8123/default?use_server_time_zone=false&use_time_zone=Asia/Shanghai", "default", "");
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO t_test VALUES (?)")
) {
preparedStatement.setLong(1, 1);
preparedStatement.execute();
}
Configuration
Environment
- Client version: 0.7.2
- Language version: java11
Hi team, I think the method in com.clickhouse.data.ClickHouseValues.java:282 is incorrect. Why should a numeric type representing a Unix timestamp, which inherently lacks timezone context, be directly converted to a LocalDateTime assuming it's in the UTC time zone?
public static LocalDateTime convertToDateTime(BigDecimal value) {
return value != null ? LocalDateTime.ofInstant(convertToInstant(value), ZoneOffset.UTC) : null;
}
The concern here is that the conversion assumes the input Unix timestamp is in UTC without verifying if this is correct for all cases, which can lead to time zone discrepancies when clients operate in different time zones.
Good day, @haishui126 ! Sorry for a delayed answer and thank you for reporting the issue!
We will look into it but this is a v1. Would you please try v2 (set by default after 0.8.0)? Thanks!
Не чего не поняла телеграмм восстановите на номере или как ?почему номер заблокирован пишет ?
Чт, 28 авг. 2025 г. в 23:21, Sergey Chernov @.***>:
chernser left a comment (ClickHouse/clickhouse-java#2065) https://github.com/ClickHouse/clickhouse-java/issues/2065#issuecomment-3234827724
Good day, @haishui126 https://github.com/haishui126 ! Sorry for a delayed answer and thank you for reporting the issue!
We will look into it but this is a v1. Would you please try v2 (set by default after 0.8.0)? Thanks!
— Reply to this email directly, view it on GitHub https://github.com/ClickHouse/clickhouse-java/issues/2065#issuecomment-3234827724, or unsubscribe https://github.com/notifications/unsubscribe-auth/BOGHYJJFGOMG4DE4YB4OIN33P5QFDAVCNFSM6AAAAACFCRIEHWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTEMZUHAZDONZSGQ . You are receiving this because you commented.Message ID: @.***>