package com.xiaoy.test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class CalendarDemo {
public static void main(String[] args) throws ParseException {
//手动输入时间
// Scanner sc = new Scanner(System.in);
// System.out.println("请输入日期:");
// String next = sc.next();
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// Date d = sdf.parse(next);
//自动获取当前系统时间
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
String s = df.format(new Date());
Date d = df.parse(s);
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(d);
c2.setTime(d);
//打印星期几
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
//判断一号是星期几
c2.set(Calendar.DATE, 1);
int j = c2.get(Calendar.DAY_OF_WEEK);
//是星期几就在前面空几格
for (int i = 1; i < j; i++) {
System.out.print("\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.print(r+"\t");
if (c2.get(Calendar.DAY_OF_WEEK)==7) {
System.out.println();
}
}
}
}