这个hutool已经封装好了,直接调就行
首先导入hutool的maven依赖
<!-- hutool 的依赖配置--> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-bom</artifactId> <version>5.8.5</version> </dependency>
写个测试类,直接调用 DateTime begin = DateUtil.beginOfDay(new Date()); DateTime end = DateUtil.endOfDay(new Date()); System.out.println(begin); System.out.println(end); 运行得到结果
2023-05-31 00:00:00 2023-05-31 23:59:59