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();
    }
相关推荐
hello_2504 天前
bug排查思路大纲
bug
秃头小饼干4 天前
关于Bug排查日记的技术文章大纲
bug
烧冻鸡翅QAQ4 天前
测试中的Bug
bug·测试
云和数据.ChenGuang5 天前
java常见SSL bug解决方案
java·bug·ssl
cat_with_cat6 天前
测试:BUG篇
bug·测试
黑客飓风6 天前
Bug排查日记的技术
bug
Wiktok6 天前
[Wit]CnOCR模型训练全流程简化记录(包括排除BUG)
python·深度学习·bug
玄尺_0076 天前
bug:uniCloud报Business Failed, 参数有误retry invoke error
数据库·bug
程序猿阿伟6 天前
《云原生边缘与AI训练场景:2类高频隐蔽Bug的深度排查与架构修复》
人工智能·云原生·bug
夕阳UPdz6 天前
深入探索 Unity 错误排查过程:从“滚动条问题”到“鼠标悬浮异常”
bug