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

SimpleDateFormat formatting of "LLLL" in English is incorrect; should be identical to "MMMM"

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • None
    • core-libs
    • 8
    • b59
    • generic
    • generic
    • Verified

        The "stand-alone" month names ("LLLL" format) in English are expected to be identical to the "context sensitive" ("MMMM" format) month names, but instead we see only numbers.

        This program:

        import java.text.*;
        import java.util.*;

        public class September {
            public static void main(String[] args) throws Throwable {
                Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2010-09-15");
                String[] formats = { "LLLL", "LLL", "LL",
                                     "MMMM", "MMM", "MM",
                };
                for (String format : formats) {
                    System.out.println(format + " -> " + new SimpleDateFormat(format, new Locale("en")).format(date));
                }
            }
        }

        prints

        LLLL -> 0009
        LLL -> 009
        LL -> 09
        MMMM -> September
        MMM -> Sep
        MM -> 09

        but we expect

        LLLL -> September
        LLL -> Sep
        LL -> 09
        MMMM -> September
        MMM -> Sep
        MM -> 09

        The month names are handled correctly in e.g. Czech.

        Spec says
        http://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html

        """
        Month: If the number of pattern letters is 3 or more, the month is interpreted as text; otherwise, it is interpreted as a number.
        """

        Workaround is to check whether LLLL yields a number and fall back to MMMM in that case.
        We have to have fall-back code anyways to continue working with jdk7.

              okutsu Masayoshi Okutsu
              martin Martin Buchholz
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: