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();
    }
相关推荐
朝新_11 小时前
【无标题】软件测试bug篇
bug
e***98571 天前
Bug侦破大会:破解技术悬案的终极策略
bug
缘友一世1 天前
精粤X99-TI D4 PLUS大板使用多显卡BIOS设置
bug·gpu·硬件·主板·x99
月明长歌1 天前
测试BUG 篇:从“怎么测”到“怎么提”,再到“怎么关”全流程
软件测试·测试开发·bug
初圣魔门首席弟子2 天前
Qt自定义控件bug记录
bug
l1t3 天前
duckdb数据库CROSS JOIN LATERAL 中使用 EXISTS子查询的一个bug
数据库·bug
Zsh-cs3 天前
苍穹外卖day11销量TOP10商品展示,前端有商品名字但无销量(已解决)
bug
数字芯片实验室4 天前
仿真器出bug了?分频时钟竞争的诡异仿真现象
fpga开发·bug
Zsh-cs4 天前
苍穹外卖day9前端订单分页查询后订单菜品不展示(已解决)
bug
北数云5 天前
北数云内测|AI 需求发布区 + Bug/建议长期征
bug·模型·智能体