JAVA-獲取當前月份的第一天和最後…
阿新 • • 發佈:2019-01-25
//得到本月的第一天
public String getMonthFirstDay() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH,
calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
SimpleDateFormat firstDay= new
SimpleDateFormat("yyyy-MM-dd");
return firstDay.format(calendar.getTime());
}
//得到本月的最後一天
public String getMonthLastDay() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH,
calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
SimpleDateFormat lastDay= new
SimpleDateFormat("yyyy-MM-dd" );
return lastDay.format(calendar.getTime());
}