Posted on 2012-03-05 14:36
yuhaibo736 阅读(638)
评论(0) 编辑 收藏
public static String lastMonFirstDay(){
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.add(Calendar.DAY_OF_MONTH, -1);
int day = cal.get(Calendar.DAY_OF_MONTH);
String months = "";
String days = "";
if (month > 1) {
month--;
} else {
year--;
month = 12;
}
if (!(String.valueOf(month).length() > 1)) {
months = "0" + month;
} else {
months = String.valueOf(month);
}
if (!(String.valueOf(day).length() > 1)) {
days = "0" + day;
} else {
days = String.valueOf(day);
}
String firstDay = "" + year + "-" + months + "-01";
String[] lastMonth = new String[2];
lastMonth[0] = firstDay;
return firstDay;
}
public static String lastMonLastDay(){
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.add(Calendar.DAY_OF_MONTH, -1);
int day = cal.get(Calendar.DAY_OF_MONTH);
String months = "";
String days = "";
if (month > 1) {
month--;
} else {
year--;
month = 12;
}
if (!(String.valueOf(month).length() > 1)) {
months = "0" + month;
} else {
months = String.valueOf(month);
}
if (!(String.valueOf(day).length() > 1)) {
days = "0" + day;
} else {
days = String.valueOf(day);
}
String lastDay = "" + year + "-" + months + "-" + days;
String[] lastMonth = new String[2];
lastMonth[1] = lastDay;
return lastDay;
}