3

I need to convert date like Mon Nov 14 13:36:01 GMT+03:00 2016 to local. So it must be 16:36:01

Date serverDate; // Mon Nov 14 13:36:01 GMT+03:00 2016

SimpleDateFormat dateFormat = new SimpleDateFOrmat("hh:mm:ss");
String result = dateFormat.formatDate(serverDate);

Result doesn't see GMT +03:00 and gives me wrong time (13:36 instead of 16:36).

Andrew F
  • 1,712
  • 2
  • 15
  • 24

1 Answers1

0

So I just needed to create formatter without ZZZZZ and set time zone to GMT.

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    final Date localDate = simpleDateFormat.parse("2016-11-11T09:48:24-05:00");

    SimpleDateFormat dateFormat = new SimpleDateFOrmat("hh:mm:ss");
    String result = dateFormat.formatDate(localDate); //12:48:24

After this code time of localDate variable will be 12:48:24 (in case of my GMT +03:00).

Andrew F
  • 1,712
  • 2
  • 15
  • 24