-1

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

Zibian Domichi
  • 185
  • 1
  • 11

1 Answers1

-1

"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...

Vadim
  • 4,027
  • 2
  • 10
  • 26
  • Those troublesome classes are now legacy, supplanted by the java.time classes. – Basil Bourque Jul 12 '17 at 14:15
  • @Basil_Bourque Which ones `javax.xml.bind.DatatypeConverter`? As I said it is one of the way (and properly working with no problems if you understand what Date class is and what TimeZone is) So... show how to do it your way before down voting. – Vadim Jul 12 '17 at 15:11
  • In 2017, there is no good reason to be promoting the bloody awful mess that is the `Date`/`Calendar` old date-time classes, no upside, no benefit. We have a replacement, an *excellent* industry-leading replacement in the java.time classes. And the replacement is *built into* Java. So why oh why continue using the old cruft? – Basil Bourque Jul 12 '17 at 15:31
  • I do not promote anything. and in 2017 there more than enough cases in real world when generic solution is required. – Vadim Jul 12 '17 at 15:51