计算一周内的日期。通过窗口输入今天日期,获取今天是周几。
GergorianCalendar类
public static void dateToWeek3() {
Scanner cin = new Scanner(System.in);
System.out.println("请输入年,月,日:");
while (cin.hasNext()) {
int year = cin.nextInt();
int month = cin.nextInt();
int day = cin.nextInt();
GregorianCalendar gre = new GregorianCalendar();
//年要减去1900,月份是0-11
Date date = new Date(year - 1900, month - 1, day);
gre.setTime(date);
//0是星期天
int weekday = gre.get(Calendar.DAY_OF_WEEK) - 1;
String[] s = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六",};
System.out.println(year + " " + month + " " + day + " " + s[weekday]);
}
}