java获取年份的第一天和最后一天

Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.DATE, 1);
String dateStr = DateUtils.format(cal.getTime(), YYYY_MM_DD);
String timeStr = DateUtils.format(cal.getTime());

System.out.println(dateStr);
System.out.println(timeStr);

cal.set(Calendar.MONTH, 11);
cal.set(Calendar.DATE, 31);

dateStr = DateUtils.format(cal.getTime(), YYYY_MM_DD);
timeStr = DateUtils.format(cal.getTime());

System.out.println(dateStr);
System.out.println(timeStr);

posted on 2017-11-14 17:56  小甜瓜安东泥  阅读(516)  评论(0编辑  收藏  举报