公历 "cal.add" 方法问题
Gregorian Calendar "cal.add" Method Issues
我目前正在尝试编写一个程序,其中 returns 从今天的当前日期算起 100 天。这是代码:
public class gregorianCalendar {
public static void main(String[] args){
Calendar cal = new GregorianCalendar();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
int weekday = cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DAY_OF_MONTH, 100);
System.out.print("100 days from today, the date will be: " + month);
System.out.print("/" + dayOfMonth);
System.out.println("/" + year);
}
}
代码的输出给出当前日期,而不是当前日期后 100 天的日期。任何帮助将不胜感激。
public class gregorianCalendar {
public static void main(String[] args){
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_MONTH, 100); // <------- add should be here
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
int weekday = cal.get(Calendar.DAY_OF_WEEK);
System.out.print("100 days from today, the date will be: " + month);
System.out.print("/" + dayOfMonth);
System.out.println("/" + year);
}
}
或
public class gregorianCalendar {
public static void main(String[] args){
Calendar cal = new GregorianCalendar();
// --------------- Current Date ------------
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
int weekday = cal.get(Calendar.DAY_OF_WEEK);
System.out.print("today, the date is: " + month);
System.out.print("/" + dayOfMonth);
System.out.println("/" + year);
// ---------- Current date + 100------------
cal.add(Calendar.DAY_OF_MONTH, 100);
System.out.print("100 days from today, the date will be: " + cal.get(Calendar.MONTH));
System.out.print("/" + cal.get(Calendar.DAY_OF_WEEK));
System.out.println("/" + cal.get(Calendar.YEAR));
}
}
我目前正在尝试编写一个程序,其中 returns 从今天的当前日期算起 100 天。这是代码:
public class gregorianCalendar {
public static void main(String[] args){
Calendar cal = new GregorianCalendar();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
int weekday = cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DAY_OF_MONTH, 100);
System.out.print("100 days from today, the date will be: " + month);
System.out.print("/" + dayOfMonth);
System.out.println("/" + year);
}
}
代码的输出给出当前日期,而不是当前日期后 100 天的日期。任何帮助将不胜感激。
public class gregorianCalendar {
public static void main(String[] args){
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_MONTH, 100); // <------- add should be here
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
int weekday = cal.get(Calendar.DAY_OF_WEEK);
System.out.print("100 days from today, the date will be: " + month);
System.out.print("/" + dayOfMonth);
System.out.println("/" + year);
}
}
或
public class gregorianCalendar {
public static void main(String[] args){
Calendar cal = new GregorianCalendar();
// --------------- Current Date ------------
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
int weekday = cal.get(Calendar.DAY_OF_WEEK);
System.out.print("today, the date is: " + month);
System.out.print("/" + dayOfMonth);
System.out.println("/" + year);
// ---------- Current date + 100------------
cal.add(Calendar.DAY_OF_MONTH, 100);
System.out.print("100 days from today, the date will be: " + cal.get(Calendar.MONTH));
System.out.print("/" + cal.get(Calendar.DAY_OF_WEEK));
System.out.println("/" + cal.get(Calendar.YEAR));
}
}