Reputation: 185
when i convert one array to json my date time change like this From 2017-07-12 11:58:07 to 2017-07-12T08:58:07.000Z
How can i parse this string to real datetime ?
I want to make like this
String Time="2017-07-12T08:58:07.000Z";
Datetime RealTime=getRealDateTime(Time);
The RealTime result is need to be 2017-07-12 11:58:07
Upvotes: -1
Views: 579
Reputation: 4120
"2017-07-12T08:58:07.000Z" - is in ISO-8601 format and represents exact same DateTime in UTC ('Z' at the end means UTC) as your 2017-07-12 11:58:07 in your Time Zone. I guess you run your program on computer in +03:00 zone.
so, one of the ways to do what you need is to use XML javax.xml.bind.DatatypeConverter
.
DatatypeConverter.parseDateTime("2017-07-12T08:58:07.000Z")
It returns Calendar so if you need java.util.Date
get it from getTime()
method as
DatatypeConverter.parseDateTime("2017-07-12T08:58:07.000Z").getTime()
From that you can print your Date in format you want through java.text.SimpleDateFormat
or any other...
Upvotes: -1