利用Calendar获取时间年和月

Calendar calendar = Calendar.getInstance();
//当前年

int year = calendar.get(Calendar.YEAR);
//当前月
int month = calendar.get(Calendar.MONTH) + 1;
//当前月的天:即当前日
int day_of_month = calendar.get(Calendar.DAY_OF_MONTH);
//当前时
int hour = calendar.get(Calendar.HOUR_OF_DAY);
//当前分
int minute = calendar.get(Calendar.MINUTE);
//当前秒
 
  
int second = calendar.get(Calendar.SECOND);
// 0:上午  1:下午
int am_pm = calendar.get(Calendar.AM_PM);
//当前年的第几周
int week_of_year = calendar.get(Calendar.WEEK_OF_YEAR);
//当前月的第几周
int week_of_month = calendar.get(Calendar.WEEK_OF_MONTH);
//当前年的第几天
int day_of_year = calendar.get(Calendar.DAY_OF_YEAR);



你可能感兴趣的:(利用Calendar获取时间年和月)