LocalDate now = LocalDate.now();//获取当前日期2023-12-31
String format =LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));//获取当前时间2023-12-31 15:44:52
int monthValue = now.getMonthValue();//返回当前的月份
int dayOfMonth = now.getDayOfMonth();//返回当前日在月份的天数int i3 = now.lengthOfMonth();
DayOfWeek dayOfWeek = now.getDayOfWeek();//返回当前是周几
int dayOfYear = now.getDayOfYear();//返回当前日在年中的天数
int i = now.lengthOfMonth();//返回当前月份的天数
int i1 = now.lengthOfYear();//返回当前年份的天数
LocalDate localDate2 = now.plusWeeks(1);//在当前的日期上加一周
LocalDate localDate = now.plusDays(1);//在当前的日期上加一天
LocalDate localDate1 = now.plusMonths(1);//在当前的日期上加一个月
LocalDate localDate3 = now.withDayOfMonth(10);//求当前月份第十天的日期
LocalDate localDate4 = now.withDayOfYear(100);//求当前年份第一百天的日期
LocalTime of = LocalTime.of(13, 11,12);//拼接时分秒
LocalDate of1 = LocalDate.of(2023, 12, 29);//拼接年月日
LocalDate parse = LocalDate.parse("2023-10-01");//解析字符串为日期
LocalDate with1 = now.with(TemporalAdjusters.firstDayOfMonth());//获取本月的第一天
LocalDate with = now.with(TemporalAdjusters.lastDayOfMonth());//获取本月的最后一天
LocalDate with2 = now.with(TemporalAdjusters.dayOfWeekInMonth(2, now.getDayOfWeek()));//获取本月的第几个周几
LocalDate with3 = now.with(TemporalAdjusters.firstDayOfNextMonth());//获取下个月的第一天
LocalDate with5 = now.with(TemporalAdjusters.firstDayOfNextMonth()).with(TemporalAdjusters.lastDayOfMonth());//获取下个月的最后一天
LocalDate with4 = now.with(TemporalAdjusters.lastInMonth(now.getDayOfWeek()));//获取指定周在本月的最后一个周的日期
LocalDate with6 = now.with(TemporalAdjusters.firstDayOfNextYear());//获取下一年的第一天
LocalDate with7 = now.with(TemporalAdjusters.lastDayOfYear()).with(TemporalAdjusters.lastDayOfYear());//获取下一年的最后一天
LocalDate with8 = now.with(TemporalAdjusters.next(now.getDayOfWeek()));//返回下一个周的日期
int i2 = now.compareTo(LocalDate.parse("2023-11-30"));//比较两个日期大小,相差几天
boolean after = now.isAfter(LocalDate.parse("2023-11-29"));//比较当前日期和指定日期的大小,大返回true,否则返回false
int i3 = now.with(TemporalAdjusters.lastDayOfMonth()).compareTo(now.with(TemporalAdjusters.firstDayOfMonth()))+1;//获取当月的天数
LocalDate localDate5 = now.withDayOfYear(364);
LocalDateTime localDateTime= LocalDateTime.now();
IntStream.range(1,LocalDate.now().lengthOfYear()+1).forEach(item->{//获取一年365天的日期
dataList.add(LocalDate.now().withDayOfYear(item).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
});标签:函数,获取,java1.8,LocalDate,int,日期,now,TemporalAdjusters From: https://www.cnblogs.com/zll-wyf/p/17882116.html