-1

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

shanabus
  • 12,989
  • 6
  • 52
  • 78
  • http://stackoverflow.com/questions/4216745/java-string-to-date-conversion – Code Whisperer Mar 26 '15 at 20:31
  • 2
    Working with time/time zones in java has been covered extensively and repeatedly in numerous places. Have you made any attempt to look up any resources that would answer your question? If so, show what you've tried so far. – tnw Mar 26 '15 at 20:32

1 Answers1

1

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

Community
  • 1
  • 1
T.Gounelle
  • 5,953
  • 1
  • 22
  • 32