日期:2014-05-20  浏览次数:20811 次

java如何算出两个日期间双休日是几月几日
如何写成一个方法,带FROM_DATE,TO_DATE两个参数,返回的数组
例:20070101这样的,请大家帮忙

------解决方案--------------------
示例如下:

import java.util.*;

public class TestCalendar {
public static void main(String[] args) {
GregorianCalendar dFrom = new GregorianCalendar(1988, 11, 8);
GregorianCalendar dTo = new GregorianCalendar(1989, 11, 8);
System.out.println();
while(dFrom.before(dTo)) {
int weekday = dFrom.get(Calendar.DAY_OF_WEEK);
if((weekday == Calendar.SATURDAY) || (weekday == Calendar.SUNDAY)) {
System.out.printf( "%04d-%02d-%02d ", dFrom.get(Calendar.YEAR), dFrom.get(Calendar.MONTH), dFrom.get(Calendar.DATE));
System.out.println();
}
dFrom.add(Calendar.DAY_OF_WEEK, 1);
}
}
}
------解决方案--------------------
楼上的代码还可以简化,第一次的周末手动计算出来,以后每次加7即可