fork download
  1. import java.time.Instant;
  2. import java.time.OffsetDateTime;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. OffsetDateTime odt = OffsetDateTime.parse("2011-12-08T02:01:02+01:00");
  7. System.out.println(odt);
  8.  
  9. // ########### In case you need Instant ###########
  10. Instant instant = odt.toInstant();
  11. System.out.println(instant);
  12.  
  13. // Java-12 onwards, you can parse the ISO-8601 compliant Date-Time with timezone
  14. // information directly into Instant
  15. instant = Instant.parse("2011-12-08T02:01:02+01:00");
  16. System.out.println(instant);
  17. }
  18. }
Success #stdin #stdout 0.1s 49296KB
stdin
Standard input is empty
stdout
2011-12-08T02:01:02+01:00
2011-12-08T01:01:02Z
2011-12-08T01:01:02Z