26 lines
626 B
Java
26 lines
626 B
Java
package com.ff.utils;
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
/**
|
|
* @author cengy
|
|
*/
|
|
public class CalculateDateDaysAgo {
|
|
|
|
public static LocalDate get(int daysToSubtract) {
|
|
return LocalDate.now().minusDays(daysToSubtract);
|
|
}
|
|
|
|
public static String getStr(int daysToSubtract) {
|
|
// 获取当前日期减去指定天数
|
|
LocalDate date = get(daysToSubtract);
|
|
|
|
// 定义日期格式
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
// 返回格式化日期字符串
|
|
return date.format(formatter);
|
|
}
|
|
}
|