//获取本月第一天
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 1);
return calendar.getTime();
//获取本月最后一天
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 0);
//获取上个月第一天
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONDAY, calendar.get(Calendar.MONDAY) - 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
//获取上月最后一天
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONDAY, calendar.get(Calendar.MONDAY) - 1);
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
//自定义时间
SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startTime = "-12-16 23:59:59";
Date startDate = format.parse(startTime)
如果觉得《java 获取当前月份的第一天_JAVA获取本月的第一天和最后一天》对你有帮助,请点赞、收藏,并留下你的观点哦!