public class test04 {
public static void main(String[] args) {
System.out.println(getCurrentMonthDay() );
System.out.println(getDayOfWeekByDate("20160912"));
System.out.println(getMonth());
System.out.println(getYear());
}
public static int getCurrentMonthDay() {
Calendar a = Calendar.getInstance();
a.set(Calendar.DATE, 1);
a.roll(Calendar.DATE, -1);
int maxDate = a.get(Calendar.DATE);
return maxDate;
}
/**
* 根据日期 找到对应日期的 星期
*/
public static String getDayOfWeekByDate(String date) {
String dayOfweek = "-1";
try {
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyyMMdd");
Date myDate = myFormatter.parse(date);
SimpleDateFormat formatter = new SimpleDateFormat("E");
String str = formatter.format(myDate);
dayOfweek = str;
} catch (Exception e) {
System.out.println("错误!");
}
return dayOfweek;
}
/**
* 获取当前月份
*/
public static int getMonth() {
Calendar a = Calendar.getInstance();
a.set(2016,7,11);
return a.get(Calendar.MONTH);
}
public static int getYear() {
Calendar a = Calendar.getInstance();
a.set(2016,7,11);
return a.get(Calendar.YEAR);
}