JAVA:int month = n.get(Calendar.MONTH)+1;なぜ1を追加しますか?

3203 ワード

 1 import java.util.*;
2 public class DateClass
3 {
4 public static void main(String args[ ])
5 {
6 Date m = new Date( );
7 System.out.println(" :"+m.toString( ));
8 Calendar n = Calendar.getInstance( );
9 int year = n.get(Calendar.YEAR);
10 int month = n.get(Calendar.MONTH)+1;
11 int day = n.get(Calendar.DATE);
12 int week = n.get(Calendar.DAY_OF_WEEK)-1;
13 Date t = n.getTime ( );
14 String week1 = new String(" ");
15 String week2=week1.substring(week, week+1);
16 String x = new String( );
17 x = " :"+year+" "+month+" "+day+" , "+week2;
18 System.out.println(" :"+t);
19 System.out.println(x);
20 }
21 }


1 MONTH 1 : public static final int MONTH get set 。 。 JANUARY, 0; 。 , 0, 1。
2 WEEK 1 : public static final int DAY_OF_WEEK get set , 。 SUNDAY、MONDAY、TUESDAY、WEDNESDAY、THURSDAY、FRIDAY SATURDAY , week week1 , DAY_OF_WEEK , , , week1 , 1 。 , 。
3 day : public static final int DATE get set , 。 DAY_OF_MONTH 。 1。 , 。
4 substring(week, week+1): public String substring(int beginIndex, int endIndex) , 。 beginIndex , endIndex - 1 。 , endIndex-beginIndex。 , 。 , , week 4, DAY_OF_WEEK( 5) 1, week week1, substring(4,5), “ , 。

転載先:https://www.cnblogs.com/ayan/archive/2011/12/22/2298505.html