java 遍历日期

时间:2025-03-28 19:16:43

java 遍历开始到结束的日期

import ;
import ;
import ;
import ;

public class Main {
	
	public static void main(String[] args) {
			//日期格式化
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			try {
				//起始日期
				Date d1 = ("2001-10-01");
				//结束日期
				Date d2 = ("2001-11-04");
				Date tmp=d1;
				Calendar dd =();
				(d1);
				//打印2001年10月1日到2001年11月4日的日期
				while(()<=()) {
					tmp=();
					((tmp));
					//天数加上1
					(Calendar.DAY_OF_MONTH, 1);
				}
			} catch (ParseException e) {
				();
			}
	}

}