如何将UTC日期/时间(字符串)解析为更具可读性的内容? [英] How can I parse UTC date/time (String) into something more readable?

查看:145
本文介绍了如何将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.

这篇关于如何将UTC日期/时间(字符串)解析为更具可读性的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆