user2874190 user2874190 - 2 years ago 119
Android Question

How to convert the string containing UTC time such as "193526"(19:35:26) to local time zone?

I am writing an app about GPS and I have to convert the string of UTC time obtained from NMEA format to local time.

The strings are formatted as "193526" which represents 19:35:26 UTC(GMT).

How can I convert it to local time such as "15:35:26 EDT"?

Answer Source

EDT TimeZone does not exist in jdk. See the answer here.

You can do the conversion this way:

    SimpleDateFormat formatUTC = new SimpleDateFormat("HHmmss");
    Date date = formatUTC.parse("193526");

    SimpleDateFormat formatEDT = new SimpleDateFormat("HH:mm:ss z");

15:35:26 GMT-04:00

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download