开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜