我想從日期從JSON格式轉換爲我的本地時間。通過使用SimpleDateFormat沒有得到適當的時間
我得到的時間爲10/27/2013 5:58:02 PM
,我需要轉換爲我的當地時間,這是+5:30
。
但是,我得到10/27/2013 6:28:02
。
我的代碼是
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("M/d/yyyy H:mm:ss a");
SimpleDateFormat longDateFormat=new SimpleDateFormat("M/d/yyyy H:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String formattedDate="";
try
{
Date myDate = simpleDateFormat.parse(mDateAndTime);
formattedDate = longDateFormat.format(myDate);
} catch (ParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
如果刪除線... simpleDateFormat.setTimeZone(TimeZone.getTimeZone( 「UTC」)); 可能是有效的。我不確定,因爲我無法測試它。請嘗試 –
thnx的回覆,但我越來越10/27/2013 0:58:02 –