【发布时间】:2013-10-27 18:18:41
【问题描述】:
我正在尝试将日期从 UTC 格式的 JSON 转换为我的本地时间。
我的时间是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"));也许它有效..我不确定,因为我无法测试它。请试一试
-
谢谢回复,但我得到了 10/27/2013 0:58:02
标签: android simpledateformat utc