不可拆除的日期,带有冒号分隔的时区 [英] Unparsable Date with colon-separated timezone

查看:119
本文介绍了不可拆除的日期,带有冒号分隔的时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析此字符串


2014-04-04T14:28:38 + 02:00


应该是ISO 8601格式。但是我无法将其解析为正确的日期。
我尝试了以下内容:

  String example =2014-04-04T14:28:38 + 02 :00
public final static SimpleDateFormat df = new SimpleDateFormat(yyyy-MM-dd'THH:mm:ssz)
日期tempDate = df.parse(示例)

但是我总是收到消息unarseable Date
我无法更改示例,因为它是一个来自webservice。



+02:00而不是+0200是否有问题?



非常感谢

解决方案

从Java7开始,处理+02:00,您可以使用以下格式: / p>

 yyyy-MM-dd'T'hh:mm:ssXXX
/ pre>

这可以在 SimpleDateFormat文档


I'm trying to parse this String

2014-04-04T14:28:38+02:00

It should be ISO 8601 format. But i can't parse it to a correct Date. I've tried the following:

   String example = "2014-04-04T14:28:38+02:00"
   public final static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz")
   Date tempDate = df.parse(example)

But I get always the message "unparseable Date" I can not change the example because it's a value from a webservice.

Could it be there is a probleme with "+02:00" instead of "+0200" ?

Thanks a lot

解决方案

Starting from Java7, to handle +02:00, you can use the following format:

"yyyy-MM-dd'T'hh:mm:ssXXX"

This can be seen in the SimpleDateFormat documentation

这篇关于不可拆除的日期,带有冒号分隔的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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