- //创建Calendar对象
- Calendar cal = Calendar.getInstance();
- //当前年
- int year = cal.get(Calendar.YEAR);
- //当前月 Calendar.MONTH从0开始
- int month = (cal.get(Calendar.MONTH))+1;
- //当前月的第几天:即当前日
- int day_of_month = cal.get(Calendar.DAY_OF_MONTH);
- //Calendar.DAY_OF_MONTH 和 Calendar.DATE 是等价的
- int date = cal.get(Calendar.DATE);
- //当前时:HOUR_OF_DAY-24小时制
- int hour24 = cal.get(Calendar.HOUR_OF_DAY);
- //HOUR-12小时制
- int hour12 = cal.get(Calendar.HOUR);
- //当前分
- int minute = cal.get(Calendar.MINUTE);
- //当前秒
- int second = cal.get(Calendar.SECOND);
- // 星期几 Calendar.DAY_OF_WEEK用数字(1~7)表示(星期日~星期六)
- int day_of_week = cal.get(Calendar.DAY_OF_WEEK)-1;
- //0-上午;1-下午
- int ampm = cal.get(Calendar.AM_PM);
- //当前年的第几周
- int week_of_year = cal.get(Calendar.WEEK_OF_YEAR);
- //当前月的星期数
- int week_of_month = cal.get(Calendar.WEEK_OF_MONTH);
- //当前月中的第几个星期
- int day_of_week_in_month = cal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
- //当前年的第几天
- int day_of_year = cal.get(Calendar.DAY_OF_YEAR);
时间: 2024-10-07 10:57:55