How can I parse a date including timezone with Joda Time

后端 未结 2 1226
半阙折子戏
半阙折子戏 2020-12-09 01:27

This snippet of code always parses the date into the current timezone, and not into the timezone in the string being parsed.

final DateTimeFormatter df          


        
2条回答
  •  一向
    一向 (楼主)
    2020-12-09 01:44

    OK, further Googling gave me the answer to my own question: use withOffsetParsed(), as so:

    final DateTimeFormatter df = DateTimeFormat
            .forPattern("EEE MMM dd HH:mm:ss 'GMT'Z yyyy");
    final DateTime dateTime = df.withOffsetParsed()
            .parseDateTime("Mon Aug 24 12:36:46 GMT+1000 2009");
    

    This works.

提交回复
热议问题