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();
    }
相关推荐
淘矿人10 小时前
Claude辅助算法设计与优化
人工智能·python·算法·microsoft·github·bug·pygame
朱穆朗17 小时前
Cmder创建npm等项目中,使用CLI的BUG
前端·npm·bug
AI 编程助手GPT2 天前
【实战】Codex 接管电脑 + Claude Routines 云端值守:一次 Bug 排查的“无人化”闭环
人工智能·gpt·ai·chatgpt·bug
minxihou2 天前
iwlwifi/iwlmld missed beacons 与 802.11ax HE beacon timing 固件 Bug
bug·协议
阿部多瑞 ABU4 天前
《智能学号抽取系统》V5.9.5 发布:精简代码,修复移动端文件读取核心 Bug
vue·html·bug
qq_452396234 天前
【工程实战】第八篇:报告美学 —— Allure 深度定制:让 Bug 定位精准到秒
开发语言·python·bug
tkokof16 天前
捉虫(Bug)小记
人工智能·深度学习·bug·游戏开发
南宫萧幕6 天前
基于上一篇文章VMware+openweb UI+ollama+docker的bug问题总结
docker·容器·bug·openweb ui