public static Date daysAgoOrAfter(Date oneday,int amount){
Calendar mon = Calendar.getInstance();
mon.setTime(oneday);
mon.add(Calendar.DATE,amount);
return mon.getTime();
}
注:前几天参数amount为负整数
后几天参数amount为正整数
测试: public static void main(String[] args){
String s="2022-04-25";
Date date = DateUtils.parseDate(s);
System.err.println("7天之前");
System.err.println(daysAgoOrAfter(date,-7));
System.err.println("6天之后");
System.err.println(daysAgoOrAfter(date,6));
}
结果输出:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)