From 9038f7dd6d9bd0de9ff595f1bbceee1ce2a8ff39 Mon Sep 17 00:00:00 2001 From: Looly Date: Wed, 29 May 2024 15:06:06 +0800 Subject: [PATCH] =?UTF-8?q?DateUtil=E5=A2=9E=E5=8A=A0offsetYear=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../src/main/java/cn/hutool/core/date/DateUtil.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d8dc6ba..636bbfce8 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ # 5.8.29(2024-05-29) ### 🐣新特性 +* 【core 】 DateUtil增加offsetYear方法 ### 🐞Bug修复 diff --git a/hutool-core/src/main/java/cn/hutool/core/date/DateUtil.java b/hutool-core/src/main/java/cn/hutool/core/date/DateUtil.java index 0abdef071..d65937d88 100755 --- a/hutool-core/src/main/java/cn/hutool/core/date/DateUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/date/DateUtil.java @@ -1439,6 +1439,18 @@ public class DateUtil extends CalendarUtil { return offset(date, DateField.MONTH, offset); } + /** + * 偏移年 + * + * @param date 日期 + * @param offset 偏移年数,正数向未来偏移,负数向历史偏移 + * @return 偏移后的日期 + * @since 5.8.29 + */ + public static DateTime offsetYear(final Date date, final int offset) { + return offset(date, DateField.YEAR, offset); + } + /** * 获取指定日期偏移指定时间后的时间,生成的偏移日期不影响原日期 *