【发布时间】:2015-08-19 20:48:42
【问题描述】:
我的程序将 UTC 时间转换为本地时间,但不是我想要的格式。我从以下链接中举了一个例子Convert UTC to current locale time
public static void main(String[] args) throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date myDate = simpleDateFormat.parse("2015-08-19 05:30:00.049 UTC+0000");
System.out.println("**********myDate:" + myDate);
}
输出:
**********myDate:Wed Aug 19 01:30:00 EDT 2015
我预期的输出格式是:
2015-08-19 01:00:14
请指教。
【问题讨论】:
-
我推荐你找Joda Time Library...
-
阅读documentation。如果你有 Java 8 切换到
java.time,但你仍然需要编写自己的格式化程序。 -
您为什么期望“01:00:14”的时间?如果您想要 EDT 时间,我希望您想要“01:30:00”来匹配未格式化的输出。