Q:

DateTimeParseException while using java.time.temporal.ChronoUnit

I am new to both stack overflow and programming. I am trying to use Java 8's to find the time difference between a TimeStamp value and Current Time Stamp Value. 
Following is my code snippet of my Scala code:
println(ChronoUnit.MILLIS.between(Instant.parse("1534274986"), Instant.now()))

It works fine until I have a test case where the epoch to Human DateTime comes down to 08/14/18 19:06:17. In that case, I get an error as:
Execution exception[[DateTimeParseException: Text '08/14/18 19:06:17' could not be parsed at index 0]]

Please help me understand why I am getting such an error. Thank you.

A:

The .parse() method of LocalDateTime is rather limited by default. That's why you run into that error posted above. But you can solve this problem by designing and applying your own particular formatter using a FormatterBuilder in between:
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;

DateTimeFormatter formatter = new DateTimeFormatterBuilder()
  .appendPattern("MM/dd/yy[ HH:mm:ss]")
  .parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
  .parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0)
  .parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)
  .toFormatter();

LocalDateTime localDateTime1 = LocalDateTime.parse("08/14/18 19:06:17", formatter);
LocalDateTime localDateTime2 = LocalDateTime.parse("08/14/18 19:08:19", formatter);

System.out.println(ChronoUnit.MILLIS.between(localDateTime1, localDateTime2));

// Result: 122000 ms

You can compare the formatted time to the current local time as well:
    LocalDateTime currentDateTime = LocalDateTime.now();
    System.out.println(ChronoUnit.MILLIS.between(localDateTime1, currentDateTime));

And if you prefer to work with Instant you can easily create your own out of the LocalDateTime instances you parsed above:
    import java.time.*;

    LocalDateTime currentDateTime = LocalDateTime.now();
    ZoneId zoneId = ZoneId.of("US/Eastern");
    ZonedDateTime zonedDateTime = ZonedDateTime.of(currentDateTime, zoneId);
    Instant instant = zonedDateTime.toInstant();

