[java]代码库
import java.util.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Main {
public static void main(String[] args) throws ParseException
{
Scanner scan = new Scanner(System.in);
int y = scan.nextInt();
int m = scan.nextInt();
Calendar a = Calendar.getInstance();//创建实例 默认是当前时刻
a.set(Calendar.YEAR, y);
a.set(Calendar.MONTH, m - 1);//因为月份是从0月开始的
int daymix = a.getActualMaximum(Calendar.DAY_OF_MONTH);//某月的最大天数
for ( int i = 1; i <= daymix; i++)
{
String dd = y + "-" + String.format("%02d", m) + "-" + String.format("%02d", i);//格式化为至少2位十进制整数
DateFormat f = new SimpleDateFormat("yyyy-MM-dd");
Date d = f.parse(dd);//类型转换
Calendar c = Calendar.getInstance();
c.setTime(d);
//DAY_OF_WEEK指这天是这周中的周几
if ( c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY )
System.out.println(dd);
}
}
}