java.time.format.DateTimeParseException: Text ‘2022-03-18 14:13:38‘ could not be parsed at index 10

LocalDateTime.parse 转化需要现将原有的String时间格式校对好,才能转化为LocalDateTime

 public static void main(String[] args) {
  String gpsTime= "2022-03-19 17:37:38";
  DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  System.out.println(LocalDateTime.parse(gpsTime,df));
  long minutes= ChronoUnit.MINUTES.between(LocalDateTime.parse(gpsTime, df),LocalDateTime.now());
  System.out.println(minutes);
 }

你可能感兴趣的:(java)