1

I am going around for a bit trying to parse this strange date format which I can't even find its name: 2016-05-03T10:40:47.559838+00:00

With Java I would convert that into "2016-05-03T10:40:47.559838+0000" (notice the last : are gone) and use the following pattern "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ", but it probably does not guarantee me UTC.

What is the correct way of parsing this date into a Joda DateTime in UTC?

Thanks!

PedroD
  • 5,670
  • 12
  • 46
  • 84
  • Well, `+00:00` or `+0000` _IS_ UTC... – Jim Garrison May 20 '16 at 16:39
  • For that single example yes – PedroD May 20 '16 at 16:41
  • 3
    You cannot parse microseconds with Joda-Time (which has only millisecond precision). By the way, the "strange" date-time format you mention is valid ISO-8601, a technical format for exchange of temporal data. – Meno Hochschild May 20 '16 at 17:00
  • @PedroD Please search Stack Overflow before posting. This issue has been covered many times already, such as [this](http://stackoverflow.com/q/2201925/642706), [this](http://stackoverflow.com/q/27064441/642706), [this](http://stackoverflow.com/q/31090946/642706), [this](http://stackoverflow.com/q/18483314/642706), [this](http://stackoverflow.com/q/9077226/642706), [this](http://stackoverflow.com/q/27270089/642706) and more. – Basil Bourque May 21 '16 at 04:40
  • The issue here is the milliseconds part :/ – PedroD May 23 '16 at 10:07

1 Answers1

1

Ignoring the microseconds issue pointed out by Meno Hochschild, use the parser to parse as normal, then call upon DateTime.withZone(DateTimeZone newZone) on the result of that to return a new instance of the DateTime converted to the desired time zone.

Brandon McKenzie
  • 1,655
  • 11
  • 26