在Java中使用偏移量解析ISO-8601 DateTime [英] Parsing ISO-8601 DateTime with offset with colon in Java
本文介绍了在Java中使用偏移量解析ISO-8601 DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在用Java解析日期时间时遇到麻烦,我使用了奇怪的日期时间格式.
如何在Java中解析2013-04-03T17:04:39.9430000+03:00
日期时间以在Java中格式化dd.MM.yyyy HH:mm
?
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?
推荐答案
有问题的奇怪"格式为 ISO-8601 -用途非常广泛.您可以使用
The "strange" format in question is ISO-8601 - its very 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屋!
查看全文