Calendar cal =Calendar.getInstance();int i = cal.get(Calendar.YEAR);//获取年System.out.println(i);int j = cal.get(Calendar.DAY_OF_YEAR);//获取一年中今天时第几天System.out.println(j);int k = cal.get(Calendar.WEEK_OF_YEAR);//一年的第几周System.out.println(k);
publicstaticvoidmain(String[] args){Calendar cal =Calendar.getInstance();//将当前月份加3。下标从0开始 0-11=1-12
cal.add(Calendar.MONTH,3);//当大于11时会从0开始System.out.println(cal.get(Calendar.MONTH)+1);}
publicstaticvoidmain(String[] args){Calendar cal =Calendar.getInstance();//gettime:获取日历时间,表达的date对象Date time = cal.getTime();System.out.println(time);}
publicstaticvoidmain(String[] args){Calendar cal =Calendar.getInstance();//getActualMaximum:获取某个字段的最大值//获取当3月中最大的天
cal.set(Calendar.MONTH,2);int i = cal.getActualMaximum(Calendar.DAY_OF_MONTH);System.out.println(i);//2020年最大的天数
cal.set(Calendar.YEAR,2020);int j = cal.getActualMaximum(Calendar.DAY_OF_YEAR);System.out.println(j);}