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

Regression: SimpleDateFormat w/lenient mode false, throws exception for Feb 29

XMLWordPrintable

    • 007
    • generic, x86
    • generic, windows_95, windows_nt, windows_xp, windows_2008, windows_vista



        Name: gsC80088 Date: 02/05/99


        SimpleDateFormat does not correctly consider leap years in the
        following code. This only occurs in jdk1.2. It works correctly
        on 1.1.6

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

        public class testdate
        {
                public testdate()
        {
        }

        public static void main(String[] arg)
        {
        SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        format.setLenient(false);

        try
        {
        String normal = "03/13/1998 12:22:43";
        String leap2000 = "02/29/2000 13:40:22";
        String leap1996 = "02/29/1996 08:15:15";
        System.out.println("Normal date:");
        Date dnorm = format.parse(normal);
        System.out.println(dnorm);

        System.out.println("2000 date:");
        Date d2000 = format.parse(leap2000);
        System.out.println(d2000);

        System.out.println("1996 date:");
        Date d1996 = format.parse(leap1996);
        System.out.println(d1996);
        }
        catch(ParseException pe)
        {
        System.out.println(pe);
        }
        catch(Exception e)
        {
        System.out.println(e);
        }
        }
        }

        output from 1.2:

        Normal date:
        Fri Mar 13 12:22:43 EST 1998
        2000 date:
        java.text.ParseException: Unparseable date: "02/29/2000 13:40:22"


        output from 1.1.6:

        Normal date:
        Fri Mar 13 12:22:43 EST 1998
        2000 date:
        Tue Feb 29 13:40:22 EST 2000
        1996 date:
        Thu Feb 29 08:15:15 EST 1996
        (Review ID: 53564)
        ======================================================================

              aliusunw Alan Liu (Inactive)
              gstone Greg Stone
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: