From f610e6e7b7451efcbccefba881c5128973dcc94c Mon Sep 17 00:00:00 2001 From: fwq <582742538@qq.com> Date: 星期一, 11 十二月 2023 10:41:37 +0800 Subject: [PATCH] 时间工具类优化 --- src/main/java/com/hx/util/DateUtil.java | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/hx/util/DateUtil.java b/src/main/java/com/hx/util/DateUtil.java index 29b40d0..4648efa 100644 --- a/src/main/java/com/hx/util/DateUtil.java +++ b/src/main/java/com/hx/util/DateUtil.java @@ -549,6 +549,7 @@ calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND,0); return calendar.getTime(); } @@ -581,6 +582,7 @@ calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); + calendar.set(Calendar.MILLISECOND,999); return calendar.getTime(); } @@ -613,13 +615,14 @@ calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND,0); return calendar.getTime(); } /** * 鑾峰彇褰撳墠骞寸殑缁撴潫鏃堕棿 * @param time 鏃堕棿 - * @return 杩斿洖鏃堕棿 鏍煎紡yyyy-MM-dd 00:00:00 + * @return 杩斿洖鏃堕棿 鏍煎紡yyyy-MM-dd 23:59:59 */ public static Date getYearEnd(Date time) { Calendar calendar = Calendar.getInstance(); @@ -629,6 +632,7 @@ calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); + calendar.set(Calendar.MILLISECOND,999); return calendar.getTime(); } @@ -668,6 +672,7 @@ calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); } @@ -680,6 +685,7 @@ calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); + calendar.set(Calendar.MILLISECOND, 999); return calendar.getTime(); } -- Gitblit v1.8.0