根据输入时间,获取当前月份的第一天和最后一天
private void dealTime(String theDay) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar cale = Calendar.getInstance();
// 获取当月第一天和最后一天
String firstday, lastday;
Date date = null;
try {
date = format.parse(theDay);
} catch (ParseException e) {
e.printStackTrace();
}
cale.setTime(date);
// 获取前月的第一天
cale.add(Calendar.MONTH, 0);
cale.set(Calendar.DAY_OF_MONTH, 1);
firstday = format.format(cale.getTime());
cale.add(Calendar.MONTH, 1);
cale.set(Calendar.DAY_OF_MONTH, 0);
lastday = format.format(cale.getTime());
System.out.println("本月第一天和最后一天分别是 : " + firstday +" 00:00:00" + " and " + lastday + " 23:59:59");
}