Java – jodatime string yyyy mm ddthh: MMSs Z to datetime
•
Java
Hi, I'm using joda time to convert my string date to a datetime object
I currently have the following string:
2014-02-16T00:17:20.000Z
How do I convert it to a datetime object?
I tried:
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZZ"); DateTime dt = formatter.parseDateTime("2014-02-16T00:17:20.000Z");
But I received the following error:
java.lang.IllegalArgumentException: Invalid format: "2014-02-16T00:17:20.000Z" is malformed at ".000Z"
Any help is greatly appreciated
Solution
For future visitors, a simpler solution:
String date = "2014-02-16T00:17:20.000Z"; DateTime dateTime = new DateTime(date);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码