环境
jvm时区:亚洲/首尔
我的测试查询
SELECT #{from}, #{to}
输入
YearMonth input = YearMonth.of(year, month)
LocalDateTime from = input.atDay(1).atStartOfDay()
LocalDateTime to = input.atEndOfMonth().atTime(LocalTime.MAX)Case1。将serverTimezone=UTC添加到jdbc url中
Case1。将serverTimezone=Asia/Seoul添加到jdbc url中
[11:03:54] [main] [DEBUG] BaseJdbcLogger.debug(143)| ==> Preparing: SELECT ?, ?
[11:03:54] [main] [DEBUG] BaseJdbcLogger.debug(143)| ==> Parameters: 2020-01-01T00:00(LocalDateTime), 2020-01-31T23:59:59.999999999(LocalDateTime)
[11:03:54] [main] [DEBUG] Slf4jSpyLogDelegator.sqlTimingOccurred(368)| com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
1. SELECT 2020-01-01T00:00, 2020-01-31T23:59:59.999999999
{executed in 3 msec}
[11:03:54] [main] [INFO ] Slf4jSpyLogDelegator.resultSetCollected(610)|
|----------------------|----------------------|
|2019-12-31 15:00:00.0 |2020-01-31 15:00:00.0 |
|----------------------|----------------------|
|----------------------|----------------------|[14:27:16] [main] [DEBUG] BaseJdbcLogger.debug(143)| ==> Preparing: SELECT ?, ?
[14:27:16] [main] [DEBUG] BaseJdbcLogger.debug(143)| ==> Parameters: 2020-01-01T00:00(LocalDateTime), 2020-01-31T23:59:59.999999999(LocalDateTime)
[14:27:16] [main] [DEBUG] Slf4jSpyLogDelegator.sqlTimingOccurred(368)| com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
1. SELECT 2020-01-01T00:00, 2020-01-31T23:59:59.999999999
{executed in 4 msec}
[14:27:16] [main] [INFO ] Slf4jSpyLogDelegator.resultSetCollected(610)|
|----------------------|----------------------|
|2020-01-01 00:00:00.0 |2020-02-01 00:00:00.0 |
|----------------------|----------------------|
|----------------------|----------------------|Q1。java LocalDateTime是否被LocalDateTimeTypeHandler转换为jdbc时间戳?
Q2。LocalDateTimeTypeHandler是否基于jdbc设置转换值?
Q3。为什么我的2020-01-31T23:59:59.999999999值转换为2020-02-01 00:00:00.0
发布于 2020-02-06 13:35:57
LocalDateTime转换为java.sql.Timestamp (不过在早期版本中是这样的)。LocalDateTime具有纳秒(9位)的精度,而MySQL的TIME、DATETIME和TIMESTAMP的精度只有微秒(6位)。你观察到的行为在MySQL文档中得到了解释。将带有小数秒部分的时间、日期或时间戳值插入同一类型的列,但小数位数较少,则会导致舍入。https://stackoverflow.com/questions/60088304
复制相似问题