简体   繁体   中英

SimpleDateFormat different behaviour depending on java version

In the netty framework there is the following code:

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.

  • on java 1.6 I get: Wed, 22-May-13 09:11:41 GM
  • on java 1.7 I get: Wed, 22-May-2013 09:11:14 GMT

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).

Try to use d-MMM-yyyy instead of d-MMM-y . I hope that difference in seconds (41 vs 14) is your typing mistake. Otherwise I cannot explain this difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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