1 <dependency> 2 <groupId>cn.hutool</groupId> 3 <artifactId>hutool-all</artifactId> 4 <version>5.1.0</version> 5 </dependency>
计算月数代码实现:
1 Date startDate = new Date(1553443200000L); 2 Date endDate = new Date(System.currentTimeMillis()); 3 long betweenMonth = DateUtil.betweenMonth(start, end, true); 4 System.out.println(betweenMonth);
1 String text1 = "2019-03-25"; 2 Temporal startDate = LocalDate.parse(text1); 3 String text2 = "2022-05-30"; 4 Temporal endDate = LocalDate.parse(text2); 5 // 方法返回为相差月份 6 long l = ChronoUnit.MONTHS.between(startDate, endDate); 7 System.out.println(l);