fork download
  1. import java.time.OffsetDateTime;
  2. import java.time.ZoneId;
  3. import java.time.ZonedDateTime;
  4. import java.time.format.DateTimeFormatter;
  5. import java.util.Locale;
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9. String strDateTime = "21-Mar-21 05:01:26 GMT";
  10. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-uu HH:mm:ss VV", Locale.ENGLISH);
  11. ZonedDateTime zdt = ZonedDateTime.parse(strDateTime, dtf);
  12. System.out.println(zdt);
  13.  
  14. // Getting ZoneId
  15. ZoneId zoneId = zdt.getZone();
  16. System.out.println(zoneId);
  17.  
  18. // If required, get OffsetDateTime from the ZonedDateTime
  19. OffsetDateTime odt = zdt.toOffsetDateTime();
  20. System.out.println(odt);
  21. }
  22. }
Success #stdin #stdout 0.14s 52504KB
stdin
Standard input is empty
stdout
2021-03-21T05:01:26Z[GMT]
GMT
2021-03-21T05:01:26Z