fork(1) download
  1. import java.time.Instant;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. String s1 = "2021-08-07T03:00:01-07:00";
  6. String s2 = "2021-08-07T15:30:00+05:30";
  7.  
  8. Instant instant1 = Instant.parse(s1);
  9. Instant instant2 = Instant.parse(s2);
  10.  
  11. System.out.println(s1 + " represents " + instant1);
  12. System.out.println(s1 + " represents " + instant2);
  13.  
  14. if (instant1.isBefore(instant2)) {
  15. System.out.println(s1 + " is before " + s2);
  16. } else if (instant1.isAfter(instant2)) {
  17. System.out.println(s1 + " is after " + s2);
  18. } else {
  19. System.out.println("The strings represent the same instants.");
  20. }
  21. }
  22. }
Success #stdin #stdout 0.11s 53700KB
stdin
Standard input is empty
stdout
2021-08-07T03:00:01-07:00 represents 2021-08-07T10:00:01Z
2021-08-07T03:00:01-07:00 represents 2021-08-07T10:00:00Z
2021-08-07T03:00:01-07:00 is after 2021-08-07T15:30:00+05:30