I'm converting UTC format to local time and I want to check if input date dateObj.lastModified()
is greater than this date Sat Jan 29 11:44:43 EST 2022
or not. Please find my code below:
I'm able to convert UTC date to local date time but I'm struggling how to check in if condition.
dateObj.lastModified() value:
2022-01-29T16:44:28Z
2022-01-30T04:54:31Z
2022-01-30T04:54:32Z
2022-01-29T16:44:42
2022-01-29T16:44:43Z
2022-01-29T16:44:43Z
MyDate.java
LocalDateTime ldt = LocalDateTime.ofInstant(dateObj.lastModified(),
ZoneId.systemDefault());
ZonedDateTime zdt = ldt.atZone(ZoneId.systemDefault());
Date output = Date.from(zdt.toInstant());
System.out.println("Date output: " +output);
Instant instant1
= Instant.parse("Sat Jan 29 11:44:43 EST 2022");
if (output.after(Date.from(instant1))) {
System.out.println("true");
}
My UTC date got converted properly in this line Date output = Date.from(zdt.toInstant());
But code is failing in if condition, can you please help how to check dateObj.lastModified is greater than this date Sat Jan 29 11:44:43 EST 2022
or not
Appreciated your help. Thanks~