hutool的bug之 DateUtil.endOfDay(DateUtil.date())

hutool 工具类DateUtil

使用时谨慎

DateUtil.endOfDay 得到的时间保存到数据时会增加一秒

首先比较下时间的long值:

这样就很明显的看出来,hutool工具类的date是毫秒位多了**.999**,保存到mysql 的时候,MySQL数据库对于毫秒大于500的数据进行进位,这样就导致了得到的时间到mysql时会增加一秒。

网络上的解决方案:
https://www.cnblogs.com/fswhq/p/mysql_1.html

代码如下:

复制代码
public static Date getEndOfDay(Date date) {
        Calendar calendarEnd = Calendar.getInstance();
        calendarEnd.setTime(date);
        calendarEnd.set(Calendar.HOUR_OF_DAY, 23);
        calendarEnd.set(Calendar.MINUTE, 59);
        calendarEnd.set(Calendar.SECOND, 59);
        calendarEnd.set(Calendar.MILLISECOND, 0); // 这一句比较关键
        return calendarEnd.getTime();
    }
相关推荐
l1t6 小时前
duckdb数据库CROSS JOIN LATERAL 中使用 EXISTS子查询的一个bug
数据库·bug
Zsh-cs8 小时前
苍穹外卖day11销量TOP10商品展示,前端有商品名字但无销量(已解决)
bug
数字芯片实验室1 天前
仿真器出bug了?分频时钟竞争的诡异仿真现象
fpga开发·bug
Zsh-cs1 天前
苍穹外卖day9前端订单分页查询后订单菜品不展示(已解决)
bug
北数云2 天前
北数云内测|AI 需求发布区 + Bug/建议长期征
bug·模型·智能体
天上掉下个牛霸天3 天前
Bug悬案:技术侦探如何破案
bug
f***24113 天前
Bug悬案:程序员破案指南
bug
e***98573 天前
Bug破案现场:技术团队的悬疑推理秀
bug
数字芯片实验室3 天前
边界值测试:一个”==”引发的芯片bug
fpga开发·bug
e***98574 天前
Bug悬案侦破大会:高效解决技术难题
bug