本帖最后由 小石姐姐 于 2018-9-29 10:34 编辑
[Java] 纯文本查看 复制代码 public class Calendar {
public static void main(String[] args) throws ParseException {
Scanner sc = new Scanner(System.in);
System.out.println("请输入日期:(2008-12-30)");
String next = sc.next();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d = sdf.parse(next);
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(d);
c2.setTime(d);
//打印星期
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
//判断1号是星期几
c2.set(Calendar.DATE, 1);
int j = c2.get(Calendar.DAY_OF_WEEK);
for (int i = 1; i < j; i++) {
System.out.println("\t");
}
//判断一个月多少天
int Max = c1.getActualMaximum(Calendar.DATE);
//判断输入的日期,加*号做标记
for (int i = 1; i < Max; i++) {
String r = i + "";
if (c1.get(Calendar.DATE) == i) {
r = i + "*";
}
c2.set(Calendar.DATE, i);
System.out.println(r + "\t");
if (c2.get(Calendar.DAY_OF_WEEK) == 7) {
System.out.println();
}
}
}
}
|