【发布时间】:2015-07-27 21:38:53
【问题描述】:
我正在尝试将 GMT 中给出的时间字符串解析为具有用户时区的新字符串。 SimpleDateFormat 将时间解析为 PST,而它应该是 PDT。打印当前时间提供正确的时区。我感觉问题可能在于使用日期,但我不确定该怎么做。
示例代码:
try {
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a z", Locale.ENGLISH);
Log.e("Current time", sdf.format(Calendar.getInstance().getTime()));
sdf.applyPattern("HHmm z");
Date date = sdf.parse("2137 GMT");
sdf.applyPattern("hh:mm a z");
Log.e("Parsed time", sdf.format(date));
}catch (Exception e){ e.printStackTrace(); }
两个日志产生:
E/Current time﹕ 02:37 PM PDT
E/Parsed time﹕ 01:37 PM PST
任何帮助将不胜感激。
【问题讨论】:
标签: android date timezone simpledateformat