用JAVA来实现日历输入年份和月份,打出本月的日历,求注释 5
1个回答
展开全部
public static int getDayCount(String dateTime) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Calendar calendar = new GregorianCalendar();
try {
calendar.setTime(sdf.parse(dateTime));
} catch (ParseException e) {
e.printStackTrace();
}
int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
return day;
}
public static void main(String[] args) throws ParseException {
String mouth = "2015-02";
int day = getDayCount(mouth);
for(int i =1;i<day+1;i++){
System.out.println(mouth+"-"+i);
}
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Calendar calendar = new GregorianCalendar();
try {
calendar.setTime(sdf.parse(dateTime));
} catch (ParseException e) {
e.printStackTrace();
}
int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
return day;
}
public static void main(String[] args) throws ParseException {
String mouth = "2015-02";
int day = getDayCount(mouth);
for(int i =1;i<day+1;i++){
System.out.println(mouth+"-"+i);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询