2016-11-10 97 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的情況下)。