String dateNow = getnowtime();//系统时间
Temporal temporal1 = LocalDate.parse(dateNow, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String ts = "yyyy-MM-dd";
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
String str = null;
str = sim.format(sim.parse(ts));
Temporal temporal2 = LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
//相差月份
long l = ChronoUnit.MONTHS.between(temporal2, temporal1);
public String getnowtime() {
LocalDateTime today = LocalDateTime.now();
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String dateStr = today.format(fmt);
return dateStr;
}
标签:相差,String,ofPattern,MM,dd,yyyy,日期,DateTimeFormatter,之间
From: https://www.cnblogs.com/liuaojun/p/16865513.html