Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JodaTime String yyyy-mm-ddThh:mmss.Z to DateTime

hi i am using Joda time to convert my string dates to DateTime objects.

I currently have the following string:

2014-02-16T00:17:20.000Z

how do i convert this to a DateTime object?

I have tried:

DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZZ");
        DateTime dt = formatter.parseDateTime("2014-02-16T00:17:20.000Z");

But i am getting the following error:

java.lang.IllegalArgumentException: Invalid format: "2014-02-16T00:17:20.000Z" is malformed at ".000Z"

Any help is greatly appreciated

like image 236
sn0ep Avatar asked Feb 17 '14 20:02

sn0ep


1 Answers

For future visitors, simpler solution:

String date = "2014-02-16T00:17:20.000Z";
DateTime dateTime = new DateTime(date);
like image 76
Bresiu Avatar answered Oct 04 '22 12:10

Bresiu