【发布时间】:2015-08-25 10:28:46
【问题描述】:
我有一个 +10:00 GMT(澳大利亚/墨尔本)的特定日期和时间,它来自 google api,格式如下:-
2015-05-12T14:00:00.000+10:00
现在,我想根据设备当前时区转换上述时间。
例如:-
以上时间+5:30 GMT(印度)应该是2015-05-12 9:30:00
我怎样才能实现它?
我下面的代码是:-
SimpleDateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sourceFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
Date parsed = null;
try {
parsed = sourceFormat.parse("2015-05-12 14:00:00");
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // => Date is in UTC now
TimeZone tz = TimeZone.getTimeZone(TimeZone.getDefault().getID());
SimpleDateFormat destFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
destFormat.setTimeZone(tz);
String result = destFormat.format(parsed);
System.out.println(result);
但结果是 2015-05-12 19:30 这是错误的..
【问题讨论】: