一:获取前一个月
/**
* @Description: 获取上个月
*/
public static String getLastMonth() {
LocalDate today = LocalDate.now();
today = today.minusMonths(1);
DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM");
return formatters.format(today);
}
二:前一天
/**
* @Description: 获取前一天
*/
public static String getDATE() {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, -1);
Date start = c.getTime();
return format.format(start);
}
三:前一个小时
/**
* @Description: 获取上1个小时
*/
public static String beforeOneHourToNowDate() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return df.format(calendar.getTime());
}
四:前一分钟
/**
* @Description: 获取上1分钟
*/
public static String beforeOneHourMINUTE() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MINUTE, (calendar.get(Calendar.MINUTE) - 1));
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return df.format(calendar.getTime());
}