import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Test {
public static SimpleDateFormat sdfa = new SimpleDateFormat("yyyy-MM-dd");
/**
* 得到本月的第一天
* @return
*/
public static String getMonthFirstDay() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar
.getActualMinimum(Calendar.DAY_OF_MONTH));
return sdfa.format(calendar.getTime());
}
/**
* 得到本月的最后一天
*
* @return
*/
public static String getMonthLastDay() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, calendar
.getActualMaximum(Calendar.DAY_OF_MONTH));
return sdfa.format(calendar.getTime());
}
public static void main(String[] args) {
System.out.println(Test.getMonthFirstDay());
System.out.println(Test.getMonthLastDay());
}
}
获得本月的第一天和最后一天
最新推荐文章于 2024-07-19 10:23:57 发布