我正在尝试打印一些东西,例如今天的日期、星期几、从现在起 100 天后的日期、从现在起一百天后的星期几、我的生日和星期几,以及我生日和一周中的那一天之后的 10,000 天。现在,我知道 GregorianCalendar 一月从 0 开始,十二月到 11。我明白了,所以当我尝试打印日期时,它说今天的日期是 2012 年 8 月 25 日而不是 12 年 9 月 25 日,但我不知道如何在不提前设置日期的情况下更正此问题月,然后实际上将月份放入 10 月而不是 9 月。
这是我目前正在处理的内容。
GregorianCalendar cal = new GregorianCalendar();
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int weekday = cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DAY_OF_MONTH, 100);
int dayOfMonth2 = cal.get(Calendar.DAY_OF_MONTH);
int month2 = cal.get(Calendar.MONTH);
int year2 = cal.get(Calendar.YEAR);
int weekday2 = cal.get(Calendar.DAY_OF_WEEK);
GregorianCalendar birthday = new GregorianCalendar(1994, Calendar.JANUARY, 1);
int dayOfMonth3 = birthday.get(Calendar.DAY_OF_MONTH);
int month3 = birthday.get(Calendar.MONTH);
int year3 = birthday.get(Calendar.YEAR);
int weekday3 = birthday.get(Calendar.DAY_OF_WEEK);
birthday.add(Calendar.DAY_OF_MONTH, 10000);
int weekday4 = birthday.get(Calendar.DAY_OF_WEEK);
int dayOfMonth4 = birthday.get(Calendar.DAY_OF_MONTH);
int month4 = birthday.get(Calendar.MONTH);
int year4 = birthday.get(Calendar.YEAR);
System.out.printf("Todays date is " +month + "/" +dayOfMonth +"/" +year +".");
System.out.printf(" It is day " +weekday +" of the week");
System.out.println("");
System.out.printf("In 100 days it will be " +month2 + "/" +dayOfMonth2 +"/" +year2 +". ");
System.out.printf("Day " +weekday2 +" of the week");
System.out.println("");
System.out.printf("My Birthday is " +month3 + "/" +dayOfMonth3 +"/" +year3 +". "+"Day " +weekday3 +" of the week");
System.out.println("");
System.out.printf("10,000 days after my birthday is " +month4 + "/" +dayOfMonth4 +"/" +year4 +". " +"Day " +weekday4 +" of the week");
所以我需要帮助更正今天日期、100 天后的日期、我的生日日期和生日后 10,000 天的月份。非常感谢任何帮助或见解。