java 输入月份和年份,就可以直接输出对应天数,用if结构
1个回答
展开全部
calendar类提供了获取某一月份天数的方法,直接调用即可。
package test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Airliner{
public static void main(String args[]){
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
calendar.setTime(sdf.parse("2015-02-01"));
System.out.println(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Airliner{
public static void main(String args[]){
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
calendar.setTime(sdf.parse("2015-02-01"));
System.out.println(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询