Java8(四):获取当前月和上个月的第一天、最后一天
获取上个月第一天和最后一天:
LocalDateTime date = LocalDateTime.now().minusMonths(1);
LocalDateTime firstday = date.with(TemporalAdjusters.firstDayOfMonth());
LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
System.out.println("firstday:"+firstday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
System.out.println("lastDay:"+lastDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
获取当前月第一天和最后一天
LocalDateTime date = LocalDateTime.now();
LocalDateTime firstday = date.with(TemporalAdjusters.firstDayOfMonth());
LocalDateTime lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
System.out.println("firstday:"+firstday.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
System.out.println("lastDay:"+lastDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
还没有评论,来说两句吧...