Fail to parse date with time zone with Joda Time
I am trying to use Joda Time both for formatting DateTime objects to String and than parse these strings back to DateTime. But I am failing to so when the pattern includes z:
DateTimeFormatter dtf = DateTimeFormat.forPattern("dd-MM-yyyy HH:mm:ss.SSS z");
String dts = dtf.print(System.currentTimeMillis());
System.out.println(dts);
DateTime dt = dtf.parseDateTime(dts);
The above code is throwing exception when the parsing the String to DateTime takes occurred.
Do you have any idea?
开发者_运维百科Yosi
You can do:
DateTime dt = new DateTime();
System.out.println(dt.toString("dd-MM-yyyy HH:mm:ss.SSS z"));
Have a look in the user guide
The Pattern is not correct, maybe try this one
DateTimeFormatter dtf = DateTimeFormat.forPattern( "dd-MM-yyyy HH:mm:ss.SSS'z" );
this worked for me
精彩评论