Home > Back-end >  Questions about the Calendar, give advice or comments
Questions about the Calendar, give advice or comments

Time:02-28

On the first code

` ` ` Java
Import the Java. Util. Calendar;

Public class CalendarDemo1 {
Public static void main (String [] args) {
C=Calendar Calendar. GetInstance ();
C.s. et,3,1 (2001);
Be sad et chtistina georgina rossetti.british poetess System. Out. Println ((Calendar. YEAR) + "YEAR" be sad et (Calendar. The MONTH) chtistina georgina rossetti.british poetess + + be sad et chtistina georgina rossetti.british poetess "MONTH" + (Calendar. The DATE) + ", ");
C.a. dd (Calendar DATE, 1);
Be sad et chtistina georgina rossetti.british poetess System. Out. Println ((Calendar. The MONTH) + be sad et chtistina georgina rossetti.british poetess "MONTH" + (Calendar. The DATE) + ", ");
}
}
` ` `
, said before the tutorial class calendar month is calculated starting from 0, but the results of this creation is beyond imagination, below is the output

Two questions,
1. In calculation without starting from 0,
2.2 there can be no 31 days in

Don't understand what is going wrong, hope ace to reassure

CodePudding user response:

C.s. et,3,1 (2001);
Time is on April 1, 2001, you don't have a plus one so output march
C.a. dd (Calendar DATE, 1);
Time to March 31, 2001, you still use + 1, so the output February 31

CodePudding user response:

reference 1/f, set up green _ response:
c.s. et,3,1 (2001);
Time is on April 1, 2001, you don't have a plus one so output march
C.a. dd (Calendar DATE, 1);
Time to March 31, 2001, you still use + 1, so the output February 31

Understand, thank you very much
  • Related