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"?
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"?
EDT TimeZone does not exist in jdk. See the answer here.
You can do the conversion this way:
SimpleDateFormat formatUTC = new SimpleDateFormat("HHmmss");
formatUTC.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = formatUTC.parse("193526");
SimpleDateFormat formatEDT = new SimpleDateFormat("HH:mm:ss z");
formatEDT.setTimeZone(TimeZone.getTimeZone("GMT-04:00"));
System.out.println(formatEDT.format(date));
15:35:26 GMT-04:00