【发布时间】:2019-10-14 06:38:34
【问题描述】:
我有一个 UTC 时间字符串(05:30:00) 将当前日期添加到字符串中并将 (UTC DateTime) 转换为 (设备时间)
注意:不使用 ZoneID
【问题讨论】:
我有一个 UTC 时间字符串(05:30:00) 将当前日期添加到字符串中并将 (UTC DateTime) 转换为 (设备时间)
注意:不使用 ZoneID
【问题讨论】:
String dateStr = "Jul 16, 2013 12:08:59 AM";
SimpleDateFormat df = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss a", Locale.ENGLISH);
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = df.parse(dateStr);
df.setTimeZone(TimeZone.getDefault());
String formattedDate = df.format(date);
注意:不要忘记包含“a”(上午/下午标记)而不是“z”(时区)。
【讨论】: