How can I parse a date including timezone with Joda Time

后端 未结 2 1225
半阙折子戏
半阙折子戏 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.

    0 讨论(0)
  • 2020-12-09 02:07

    also you can chose:

    // parse using the Paris zone
    DateTime date = formatter.withZone(DateTimeZone.forID("Europe/Paris")).parseDateTime(str);
    
    0 讨论(0)
提交回复
热议问题