日期:2014-05-19 浏览次数:20746 次
import java.util.*; import java.text.*; public class Test { public static void main(String[] args) throws Throwable { String s = "2012-04-20"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date d = sdf.parse(s); Calendar c = Calendar.getInstance(); c.setTime(d); int min = c.getActualMinimum(Calendar.DAY_OF_MONTH); int max = c.getActualMaximum(Calendar.DAY_OF_MONTH); c.set(Calendar.DAY_OF_MONTH, min); int workDays = 0; for (int i=0; i<max; i++) { int wd = c.get(Calendar.DAY_OF_WEEK); if (wd != Calendar.SATURDAY && wd != Calendar.SUNDAY) { workDays++; } c.add(Calendar.DAY_OF_MONTH, 1); } System.out.printf("work days = %d\n", workDays); } }