日期如下:
25 / apr / 18 10:24 AM
这是我尝试使用
的代码DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yy HH:mm");
LocalDate open = LocalDate.parse(openTime.toString(), dtf);
LocalDate now = LocalDate.now();
now = dtf.format(now); // <-- Can't do this as it's apparently a string and not a LocalDate
elapsedDays = ChronoUnit.DAYS.between(now, open)
答案 0 :(得分:2)
首先,您的模式需要支持从您的示例判断AM / PM,其次,您现在不需要解析,因为您希望将其用作LocalDate实例。
String input = "22/Apr/18 10:24 AM";
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MMM/yy hh:mm a", Locale.ENGLISH);
LocalDate open = LocalDate.parse(input, dtf);
LocalDate now = LocalDate.now();
long diff = ChronoUnit.DAYS.between(open, now);