2016-11-10 99 views
0

我需要将日期转换为Mon Nov 14 13:36:01 GMT + 03:00 2016至本地。所以它一定是16:36:01将GMT +日期转换为android的本地日期

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

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

结果看不到GMT +03:00,并给我错误的时间(13:36而不是16:36)。

+1

什么是您当地的时区?如果你在GMT + 3,那么13:36:01是正确的。 – Henry

+0

是的,它已经在日期中显示了13:36的GMT +3。 – aleksandrbel

回答

0

所以我只需要创建没有ZZZZZ的格式化程序并将时区设置为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 

这段代码的localDate变量的时间将是12:48:24(在我的格林尼治标准时间+03:00的情况下)。