I am attempting to capture the time before and after I check a timestamp value on a webpage and then confirm my timestamp falls in between those times. However, I'm struggling to convert my String timestamp into a comparable format in a clean way.
Instant b4 = Instant.now();
//My code submites a file that then triggers the timestamp. I retrieve it as a string
//exa string"9/25/2020, 11:03:18 AM"
DateTimeFormatter dtf = DateTimeFormatter
.ofPattern("MM/dd/yyyy, HH:mm:ss a")
.withZone(ZoneId.systemDefault());
Instant instantTimestamp = Instant.from(dtf.parse(timeStamp));
Instant after = Instant.now();
if (instantTimestamp.isAfter(b4) && instantTimestamp.isBefore(after)) {
testPass = true;
}
Assert.assertTrue(testPass);
My Error: java.time.format.DateTimeParseException: Text '9/25/2020, 12:46:00 PM' could not be parsed at index 0