Browse Source

提交日期工具类

develop
wanjing 9 months ago
parent
commit
c264fa5049
1 changed files with 30 additions and 0 deletions
  1. +30
    -0
      tuoheng-common/tuoheng-common-core/src/main/java/com/tuoheng/common/core/utils/DateUtils.java

+ 30
- 0
tuoheng-common/tuoheng-common-core/src/main/java/com/tuoheng/common/core/utils/DateUtils.java View File

@@ -435,4 +435,34 @@ public final class DateUtils extends org.apache.commons.lang3.time.DateUtils {
return DateUtils.parseDateToStr(YYYY_MM_DD_HH_MM_SS, closest);
}

public static Integer getYear() {
LocalDate localDate = LocalDate.now();
return localDate.getYear();
}

public static Integer getMonth() {
LocalDate localDate = LocalDate.now();
return localDate.getMonthValue();
}

/**
* 获得多少个月以前(正数)或以后(负数)的时间,格式化成yyyy-MM-dd HH:mm:ss:SS
*/
public static String getMonthBefore(int month) {
Calendar calendar = Calendar.getInstance();//日历对象
calendar.setTime(date); //设置当前日期
calendar.add(Calendar.MONTH, month);//为负月份减,为正月份加
return sdf.format(calendar.getTime());
}

/**
* 获得多少年以前(正数)或以后(负数)的时间,格式化成yyyy-MM-dd HH:mm:ss:SS
*/
public static String getYearBefore(int year) {
Calendar calendar = Calendar.getInstance();//日历对象
calendar.setTime(date); //设置当前日期
calendar.add(Calendar.YEAR, year); //为负年减,为年份加
return sdf.format(calendar.getTime());
}

}

Loading…
Cancel
Save