java中利用Calendar获得月份的时候为什么要加1? package C; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class GetTime { public static void main(String []args) { Date taday=new Date(); //获取当前日期和时间 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(taday); System.out.println("当前时间为:"+dateString);
long currentTime=System.currentTimeMillis(); //当前时间的毫秒数
Date tomorrow=new Date(currentTime+24*60*60*1000); System.out.println("明天是"+tomorrow.toString());
Calendar now=Calendar.getInstance(); int year=now.get(Calendar.YEAR); int month=now.get(Calendar.MONTH)+1;//?为什么要加1 int day=now.get(Calendar.DATE); System.out.println("今天是"+year+"年"+month+"月"+day+"日");
int week=now.get(Calendar.DAY_OF_WEEK); switch(week) { case 1: System.out.println("星期日"); break; case 2: System.out.println("星期一"); break; case 3: System.out.println("星期二"); break; case 4: System.out.println("星期三"); break; case 5: System.out.println("星期四"); break; case 6: System.out.println("星期五"); break; case 7: System.out.println("星期六"); break; case 8: System.out.println("星期日"); break; } } }