奇怪的日期和时间解析问题的SimpleDateFormat [英] Strange date and time parsing problem with SimpleDateFormat

查看:133
本文介绍了奇怪的日期和时间解析问题的SimpleDateFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题解析ISO8601日期和时间SimpleDateFormat的时候。有关code是:

I have a strange problem when parsing a ISO8601 date and time with SimpleDateFormat. The relevant code is:

public class DateHelper
{
    private static SimpleDateFormat iso8601formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    public static Date parseISO8601(String date) throws ParseException
    {
   Date result = iso8601formatter.parse(date);
   return result;
    }
}

有关输入我给它一个字符串

For input I'm giving it a string

2010-09-06T15:30:00+02:00

而作为回报,我得到一个Date对象日期设置为6日2010年1月以13:30的时间和格林尼治标准​​时间的时区+ 00:00

And as a return I get a Date object with date set to 6th of January 2010 with time of 13:30 and timezone of GMT+00:00.

编辑:我也尝试过使用2010-09-06T15:30:00 + 0200,与相同的结果。

I also tried using "2010-09-06T15:30:00+0200" with same results.

令人困惑的事情是,日期设定是部分正确的,只是这个月设置错误。

Confusing thing is, that the date set is partially correct, just the month is set wrongly.

问题显示在Android 1.6和Android 2.2。

The issue is shown on Android 1.6 and Android 2.2.

我该如何解决这个问题?

How can I fix it?

推荐答案

如果您使用毫米为一个月,而不是 MM <你的问题是可重复执行/ code>。

Your problem is reproduceable if you use mm for month instead of MM.

所以我怀疑这个问题的原因是存在的,你没有运行的code,你认为你正在运行的版本。重新编译和重新执行code,你在你的问题已经。这是正确的。

So I suspect that the cause of the problem is there and that you're not running the version of the code you think you're running. Recompile and reexecute the code as you've in your question. It's correct.

这篇关于奇怪的日期和时间解析问题的SimpleDateFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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