Parse date with AEDT and AEST time zone in java

前端 未结 1 1325
情书的邮戳
情书的邮戳 2020-12-21 06:19

I am trying to parse a string of format

Thu Apr 07 11:45:28 AEST 2016

into date object. My code looks like following:

Simpl         


        
相关标签:
1条回答
  • 2020-12-21 07:07

    Using the java.time framework (JSR 310), you can do:

    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("EEE MMM d HH:mm:ss zzz yyyy");
    ZonedDateTime zdt = ZonedDateTime.parse("Sat Feb 01 15:00:19 AEDT 2014", dtf);
    System.out.println(zdt);
    

    …which prints:

    2014-02-01T15:00:19+11:00[Australia/Sydney]

    Though why it picks Sydney instead of Melbourne I am not sure.

    0 讨论(0)
提交回复
热议问题