悠然哈哈哈

导航

获取当前日期前100天的日期

public List getDatePeriod(Date date, int beforeDays){
List datePeriodList = new ArrayList();
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int inputDayOfYear = cal.get(Calendar.DAY_OF_YEAR);
for(int i=beforeDays-1;i>=0;i--){
cal.set(Calendar.DAY_OF_YEAR , inputDayOfYear-i);
datePeriodList.add(dateFormat.format(cal.getTime()));
}
return datePeriodList;
}

public static void main(String[] agrs){
FindDates test = new FindDates();
//当前日期前100天的日期
List dateList= test.getDatePeriod(new Date(), 100);
for(Object date:dateList){
System.out.println(date);
}

}

在整理资料,不记得这代码在哪里copy的了,原主请见谅

 

posted on 2016-12-08 14:50  悠然886  阅读(501)  评论(0编辑  收藏  举报