如何将UTC日期/时间(字符串)解析为更具可读性的内容?

问题描述:

我有一个日期和时间的字符串: 2011-04-15T20:08:18Z 。我不太了解日期/时间格式,但我认为,如果我错了,请纠正我,这是它的UTC格式。

I have a String of a date and time like this: 2011-04-15T20:08:18Z. I don't know much about date/time formats, but I think, and correct me if I'm wrong, that's its UTC format.

我的问题:用Java解析这种更正常格式的最简单方法是什么?

My question: what's the easiest way to parse this to a more normal format, in Java?

您所拥有的是 ISO-8601 日期格式,这意味着你可以使用 SimpleDateFormat

What you have is an ISO-8601 date format which means you can just use SimpleDateFormat

DateFormat m_ISO8601Local = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

然后你可以使用 SimpleDateFormat.parse() 。另外,这里有一些博客文章,其中包含一些可能有用的示例。

And then you can just use SimpleDateFormat.parse(). Also, here is a blog post with some examples that might help.

更新:

在使用此解决方案之前,请阅读以下评论。

Read the comments below before using this solution.