From ca698f88c0632a85bca91c7ea12267c83889f673 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期五, 16 十二月 2022 16:34:57 +0800 Subject: [PATCH] 新增时间算法 --- src/main/java/com/hx/util/DateUtil.java | 26 ++++++++++++++++++++------ 1 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hx/util/DateUtil.java b/src/main/java/com/hx/util/DateUtil.java index befbd61..3bf51a3 100644 --- a/src/main/java/com/hx/util/DateUtil.java +++ b/src/main/java/com/hx/util/DateUtil.java @@ -572,8 +572,7 @@ /** * 鑾峰彇褰撳墠鏈堢殑缁撴潫鏃堕棿 - * - * @param date 0鎷垮彇褰撴湀锛屾浠h〃鍚庯紝璐熶唬琛ㄥ墠锛屽�间负鍑犱釜锛堟湀锛� + * @param date 鐐瑰墠鏃堕棿 * @return 杩斿洖鏃堕棿 鏍煎紡yyyy-MM-dd 23:59:59 */ public static Date getMonthEnd(Date date) { @@ -588,7 +587,6 @@ /** * 鑾峰彇褰撳墠鏈堢殑缁撴潫鏃堕棿 - * * @param num 0鎷垮彇褰撴湀锛屾浠h〃鍚庯紝璐熶唬琛ㄥ墠锛屽�间负鍑犱釜锛堟湀锛� * @return 杩斿洖鏃堕棿 鏍煎紡yyyy-MM-dd 23:59:59 */ @@ -619,8 +617,24 @@ return calendar.getTime(); } - /** + * 鑾峰彇褰撳墠骞寸殑缁撴潫鏃堕棿 + * @param time 鏃堕棿 + * @return 杩斿洖鏃堕棿 鏍煎紡yyyy-MM-dd 00:00:00 + */ + public static Date getYearEnd(Date time) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(time); + calendar.set(Calendar.MONTH, 12); + calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DATE)); + calendar.set(Calendar.HOUR_OF_DAY, 23); + calendar.set(Calendar.MINUTE, 59); + calendar.set(Calendar.SECOND, 59); + return calendar.getTime(); + } + + + /**杩欏ぉ鐨勫紑濮嬫椂闂� * 鏃ユ湡2000-01-01鍙�2000-01-01 00:00:00 */ public static String dayToStart(Date date) { @@ -633,7 +647,7 @@ return sdf.format(calendar.getTime()); } - /** + /**杩欏ぉ鐨勬渶鍚庢椂闂� * 鏃ユ湡2000-01-01鍙�2000-01-01 23:59:59 */ public static String dayToEnd(Date date) { @@ -646,7 +660,7 @@ return sdf.format(calendar.getTime()); } - /** + /**杩欏ぉ鐨勬渶鍚庢椂闂� * 鏃ユ湡2000-01-01鍙�2000-01-01 23:59:59 */ public static Date dayToEndDate(Date date) { -- Gitblit v1.8.0