LocalDateTime获取当日00:00、结束时间23.59与当月第一天00.00,月末最后一天23.59
localDdate格式为字符串
//localDateTime格式为字符串
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
time.format(df)--------------2020-09-04 18:57:14
LocalDateTime 获取当天开始时间00.00 ~当天结束时间23.59
/**
* 获取当天开始时间00.00 ~当天结束时间23.59
* @return
*/
public static Map<String,String> today(){
LocalDateTime today_start = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
LocalDateTime today_end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
DateTimeFormatter time = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String todayStart=time.format(today_start);
String todayEnd = time.format(today_end);
Map<String, String> map = new HashMap<>();
map.put("todayStart",todayStart);
map.put("todayEnd",todayEnd);
return map;
}
LocalDateTime 获取本月第一天开始时间00.00 ~本月最后一天结束时间23.59
/**
*
* 获取本月第一天开始时间00.00 ~本月最后一天结束时间23.59
* @return
*/
public static Map<String,String> moth(){
LocalDateTime now = LocalDateTime.now();
LocalDateTime beginDateTime = now.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
LocalDateTime endDateTime = now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
DateTimeFormatter time = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String startMoth = time.format(beginDateTime);
String endMoth = time.format(endDateTime);
Map<String, String> map = new HashMap<>();
map.put("startMoth",startMoth);
map.put("endMoth",endMoth);
return map;
}
LocalDateTime 获取上个月第一天开始时间00.00 ~上个月最后一天结束时间23.59
/**
* 获取上个月第一天开始时间00.00 ~上个月最后一天结束时间23.59
* @return
*/
public static Map<String,String> lastMoth(){
LocalDateTime date = LocalDateTime.now().minusMonths(1);
LocalDateTime firstDay = date.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
String startLastMonth = firstDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
String endLastMonth = lastDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
Map<String, String> map = new HashMap<>();
map.put("startLastMonth",startLastMonth);
map.put("endLastMonth",endLastMonth);
return map;
}