日期比较

来源:互联网 发布:淘宝如何代理话费充值 编辑:程序博客网 时间:2024/05/21 18:37

3.*******************************时间比较大小********************************

public class Test {

public static void main(String[] args) {

String startDate = "2013-07-10";

String endDate = "2013-07-20";

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

Calendar cal1 = Calendar.getInstance();

Calendar cal2 = Calendar.getInstance();

try {

cal1.setTime(sdf.parse(startDate));

cal2.setTime(sdf.parse(endDate));

} catch (ParseException e) {

e.printStackTrace();

}

int count = 0;

while(cal1.before(cal2)){

cal1.add(Calendar.DATE, 1);

count++;

Date tempdate = cal1.getTime();

System.out.println("count="+count+"   startDate="+sdf.format(tempdate));

 

 

}

}