Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6609750

[Fmt-De] SimpleDateFormat.format() doesn't handle pattern "y" correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 1.4.2, 5.0
    • core-libs
    • b64
    • x86
    • windows_98, windows_xp
    • Verified

      FULL PRODUCT VERSION :
      java version "1.5.0_07"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      SimpleDateFormat.format(Date) with pattern "y" prints 07 instead of 7.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      SimpleDateFormat sdf = new SimpleDateFormat();
      sdf.applyPattern("y");
      System.out.println(sdf.format(new Date()));


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.SimpleDateFormat;
      import java.util.Date;

      public class SDFTest
      {

      public static void main(String[] args) {
      Date date = new Date();
      SimpleDateFormat sdf = new SimpleDateFormat();
      String format = "y";
      sdf.applyPattern(format);
      System.out.println("format=" + format + "\t" + sdf.format(date));
      format = "yy";
      sdf.applyPattern(format);
      System.out.println("format=" + format + "\t" + sdf.format(date));
      format = "yyy";
      sdf.applyPattern(format);
      System.out.println("format=" + format + "\t" + sdf.format(date));
      format = "yyyy";
      sdf.applyPattern(format);
      System.out.println("format=" + format + "\t" + sdf.format(date));
      format = "yyyyy";
      sdf.applyPattern(format);
      System.out.println("format=" + format + "\t" + sdf.format(date));
      }

      }
      ---------- END SOURCE ----------

            peytoia Yuka Kamiya (Inactive)
            okutsu Masayoshi Okutsu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: