Java 时间处理(三):获取年份、月份等
程序员文章站
2022-06-07 12:36:35
...
Calendar cal = Calendar.getInstance();//实例化日历
int day = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
int day_of_week = cal.get(Calendar.DAY_OF_WEEK);
int day_of_month = cal.get(Calendar.DAY_OF_MONTH);
int day_of_year = cal.get(Calendar.DAY_OF_YEAR);
System.out.println("当前日期:" + cal.getTime());
System.out.println("日期:" + day);
System.out.println("月份:" + month);
System.out.println("年份:" + year);
System.out.println("一周中的第几天:" + day_of_week);
System.out.println("一个月中的第几天:" + day_of_month);
System.out.println("一年中的第几天:"+ day_of_year);
//当前日期:Tue Jul 23 15:34:19 CST 2019
//日期:23
//月份:7
//年份:2019
//一周中的第几天:3
//一个月中的第几天:23
//一年中的第几天:204