JAVA:int month = n.get(Calendar.MONTH)+1;为何要加1?
JAVA:int month = n.get(Calendar.MONTH)+1;为何要加1?
import java.util.*;
public class DateClass
{
public static void main(String args[ ])
{
Date m = new Date( );
System.out.println("现在是:"+m.toString( ));
Calendar n = Calendar.getInstance( );
int year = n.get(Calendar.YEAR);
int month = n.get(Calendar.MONTH)+1;
int day = n.get(Calendar.DATE);
int week = n.get(Calendar.DAY_OF_WEEK)-1;
Date t = n.getTime ( );
String week1 = new String("日一二三四五六");
String week2=week1.substring(week,week+1);
String x = new String( );
x = "现在是:"+year+"年"+month+"月"+day+"日,星期"+week2;
System.out.println("现在是:"+t);
System.out.println(x);
}
}
为什么定义month和week时要加1和减1?而定义day时不用啊?substring(week,week+1)具体啥意思啊?
偶是个新手,问题有些笨,还希望不吝赐教啊!
MONTH加1的原因:public static final int MONTH指示月份的 get 和 set 的字段数字.这是一个特定于日历的值.在格里高利历和罗马儒略历中一年中的第一个月是 JANUARY,它为 0;最后一个月取决于一年中的月份数.简单来...