import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;
/**
* 可视化日历
*
* @author Administrator
*
*/
public class Demo1 {
public static void main(String[] args) {
System.out.println("输入你要查找的日期(按照格式2000-1-1)");
Scanner scanner = new Scanner(System.in);
String day = scanner.nextLine();
// String day = "1995-10-26";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
Date date = dateFormat.parse(day);
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
int temp = calendar.get(calendar.DATE);
calendar.set(calendar.DATE, 1); // 当月的星期一
// System.out.println(calendar.get(calendar.DAY_OF_WEEK));
// //获取一号是星期几
int maxDate = calendar.getActualMaximum(calendar.DATE);
System.out.println("本月一共:"
+ calendar.getActualMaximum(calendar.DATE) + "天");// 获取本月最大的天数
System.out.println("日" + "\t" + "一" + "\t" + "二" + "\t" + "三"
+ "\t" + "四" + "\t" + "五" + "\t" + "六" + "\t");
for (int i = 0; i < calendar.get(calendar.DAY_OF_WEEK) - 1; i++) {
System.out.print("\t");
}
for (int i = 1; i <= maxDate; i++) {
if (i == temp) {
System.out.print("*");
}
System.out.print(i + "\t");
int w = calendar.get(calendar.DAY_OF_WEEK);
if (w == calendar.SATURDAY) {
System.out.println();
}
calendar.add(calendar.DATE, 1);
}
} catch (ParseException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
09-08
09-08
09-08