SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
calendar.set(Integer.valueOf(2015),Integer.valueOf(2)-1 ,1); //月份从0开始,所以2代表的是3月份,要-1
System.out.println(sdf.format(calendar.getTime())); //2015-02-01
calendar.roll(Calendar.DATE, -1);
System.out.println(sdf.format(calendar.getTime())); //2015-02-28
int days = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println(days); //28
时间: 2024-10-09 17:07:11