在java中解析ISO-8601 DateTime [英] Parsing ISO-8601 DateTime in java

查看:92
本文介绍了在java中解析ISO-8601 DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在java中解析日期时间有麻烦,我有一个奇怪的日期时间格式。
如何解析 2013-04-03T17:04:39.9430000 + 03:00 日期时间在java格式化 dd.MM。 yyyy HH:mm in java?

解决方案

你所说的奇怪实际上是相当广泛使用的 ISO-8601 格式。您可以使用 SimpleDateFormat 以大多数方式重新格式化:

  SimpleDateFormat inFormat = new SimpleDateFormat(yyyy-MM-dd'THH:mm:ssZ); 
DateTime dtIn = inFormat.parse(dateString}); //其中dateString是ISO-8601格式的日期
SimpleDateFormat outFormat = new SimpleDateFormat(dd.MM.yyyy HH:mm);
String dtOut = outFormat.format(dtIn);
//如果您需要与它进行交互,则将其解析为DateTime对象

会给你你提到的格式。


I have a trouble with parsing date time in java, I have a strange date time format. How can I parse 2013-04-03T17:04:39.9430000+03:00 date time in java to format dd.MM.yyyy HH:mm in java?

解决方案

The "strange" format you're speaking of is actually the ISO-8601 format, which is fairly widely used. You can use SimpleDateFormat to reformat it in most way you please:

SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
DateTime dtIn = inFormat.parse(dateString});  //where dateString is a date in ISO-8601 format
SimpleDateFormat outFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
String dtOut = outFormat.format(dtIn);
//parse it into a DateTime object if you need to interact with it as such

will give you the format you mentioned.

这篇关于在java中解析ISO-8601 DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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