获取指定时间前n天的日期 (年月日)
public static String getSpecialDaysBeforeTime(int day,String time) {
Calendar now = Calendar.getInstance();
Date date = HandleTimeUtil.parseDate(time);
now.setTime(date);
now.add(Calendar.DAY_OF_MONTH, -day);
String endDate = new SimpleDateFormat("yyyy-MM-dd").format(now.getTime());
return endDate;
}
知是行之始,行是知之成!
该方法使用Java的Calendar类来获取给定时间之前n天的日期。首先获取当前时间,然后解析输入的时间字符串,设置到Calendar对象,接着回溯指定的天数,最后格式化为yyyy-MM-dd的字符串返回。
6655

被折叠的 条评论
为什么被折叠?



