JAVA有自己的工具类进行了计算,如下:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DateUtil {
public static int getDaysOfMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
}
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM");
System.out.println(getDaysOfMonth(sdf.parse("2015-02")));
}
}
网友评论