public static int getDaysByMonth(String time){
Calendar rightNow = Calendar.getInstance();
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM"); //如果写成年月日的形式的话,要写小d,如:"yyyy/MM/dd"
try {
rightNow.setTime(simpleDate.parse(time)); //要计算你想要的月份,改变这里即可
} catch (Exception e) {
e.printStackTrace();
}
int days = rightNow.getActualMaximum(Calendar.DAY_OF_MONTH);
return days;
}
public static List<String> getWeekDay(String str) {
List<String> list = new ArrayList<String>();
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = sdf.parse(str);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
c.setTime(date);
int week = c.get(Calendar.WEEK_OF_MONTH);//获取是本月的第几周
System.out.println("今天是本月的第" + week + "周");
String nReturn;
switch (c.get(Calendar.DAY_OF_WEEK)) {
case 1:
nReturn = "7";
break;
case 2:
nReturn = "1";
break;
case 3:
nReturn = "2";
break;
case 4:
nReturn = "3";
break;
case 5:
nReturn = "4";
break;
case 6:
nReturn = "5";
break;
case 7:
nReturn = "6";
break;
default:
nReturn = null;
break;
}
list.add(String.valueOf(String.valueOf(week)));
list.add(nReturn);
System.out.println(nReturn);
return list;
}