From the line I am taking the date in the format:

"yyyy-MM-dd'T'HH:mm:ss" 

When I try to compare this date with LocalDateTime.now() I always get the current date after the date from the line. Plus the date from the line gives 0 when .getNano()

Example:

 DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss") String dateStr = "2012-01-20T02:15:12"; LocalDateTime date = LocalDateTime.parse(dateStr, DATE_FORMAT); 

What am I doing wrong?

  • 3
    Does it bother you that there is no nanosecond line at all? - Vladimir Martyanov
  • Confused, of course. How then to compare these dates? - Artyom Chebotaryov
  • Well, if there is no nanosecond in the input line, it means you don’t have them anywhere, there is no magic here. If you want to compare with the current local time, then set it nanoseconds to 0 LocalDateTime.now().withNano(0) - Alexandr
  • @Alexandr thanks, figured it out. Used 'DatatypeConverter.parseDatetime ()' - Artyom Chebotaryov

0