简体   繁体   English

SimpleDateFormat的不同行为取决于Java版本

[英]SimpleDateFormat different behaviour depending on java version

In the netty framework there is the following code: 在netty框架中,有以下代码:

final class CookieDateFormat extends SimpleDateFormat {

    private static final long serialVersionUID = 1789486337887402640L;

    CookieDateFormat() {
        super("E, d-MMM-y HH:mm:ss z", Locale.ENGLISH);
        setTimeZone(TimeZone.getTimeZone("GMT"));
    }
}

The issue I am having is that the above's output varies depending on the version of the jvm when I run it. 我遇到的问题是,上面的输出根据我运行jvm的版本而有所不同。

  • on java 1.6 I get: Wed, 22-May-13 09:11:41 GM 在Java 1.6上我得到:星期三,13年5月22日09:11:41 GM
  • on java 1.7 I get: Wed, 22-May-2013 09:11:14 GMT 在Java 1.7上我得到:2013年5月22日星期三,格林尼治标准时间

Is there any way to change the behavior on java 1.6 to match the output of 1.7 without having to alter the code (since I would prefer not having to change code in netty). 有什么方法可以更改java 1.6上的行为以匹配1.7的输出而不必更改代码(因为我宁愿不必更改netty中的代码)。

Try to use d-MMM-yyyy instead of d-MMM-y . 尝试使用d-MMM-yyyy而不是d-MMM-y I hope that difference in seconds (41 vs 14) is your typing mistake. 我希望您输入错误的时间以秒为单位(41 vs 14)。 Otherwise I cannot explain this difference. 否则,我无法解释这种差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM