我正在编写一个关于GPS的应用程序,我必须将从NMEA格式获得的UTC时间字符串转换为当地时间。
字符串的格式为" 193526"代表格林威治标准时间19:35:26。( 如何将其转换为当地时间,例如" 15:35:26 EDT"?
答案 0 :(得分:0)
在jdk中不存在EDT TimeZone
。请参阅the answer here。
您可以通过这种方式进行转换:
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