赞
踩
解决方法是在实例化Calendar类之后,要先调用clear()方法清空缓存。
- Calendar calendar=Calendar.getInstance();
- calendar.clear();
- calendar.set(Calendar.YEAR, 2017);
- calendar.set(Calendar.MONTH, 1);
- int firstDay=calendar.getActualMinimum(calendar.DAY_OF_MONTH);
- int lastDay=calendar.getActualMaximum(calendar.DAY_OF_MONTH);
- System.out.println(2+"月第一天是:"+firstDay);
- System.out.println(2+"月最后一天是:"+lastDay);
- calendar.set(Calendar.DAY_OF_MONTH, lastDay);
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
- System.out.println(sdf.format(calendar.getTime()));
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。