Java and dates ?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Java and dates ?

Hybrid View

  1. #1
    Jean-Philippe Forti Guest

    Java and dates ?

    Could someone tell me why java convert the following date 30.06.2001
    (MM.DD.YYYY) in 06.06.2003 ?

    I use the followin code :

    import java.util.Date;
    import java.util.Calendar;
    import java.text.SimpleDateFormat;
    import java.text.ParsePosition;

    public class DateTest
    {

    public DateTest()
    {
    }

    public static void main(String[] args)
    {
    String sDate = "30.06.2001";
    System.out.println( sDate);
    SimpleDateFormat localFormatter = new SimpleDateFormat("MM.dd.yyyy");
    ParsePosition pos = new ParsePosition(0);
    Date myDate = localFormatter.parse(sDate, pos);
    System.out.println( localFormatter.format(myDate) );
    }
    }

    It produces the following outup :
    30.06.2001
    06.06.2003


    Any explanation is welcomed.


    --
    Jean-Philippe Forti
    EIM SA Switzerland
    jpforti@eim.nospam (replace nospam with ch)



  2. #2
    Paul Clapham Guest

    Re: Java and dates ?

    The 6th day of the 30th month of 2001: that's two years later than the 6th
    day of the 6th month of 2001.

    PC2

    "Jean-Philippe Forti" <jpforti@eim.nospam> wrote in message
    news:3adda47d$1@news.devx.com...
    > Could someone tell me why java convert the following date 30.06.2001
    > (MM.DD.YYYY) in 06.06.2003 ?
    >
    > I use the followin code :
    >
    > import java.util.Date;
    > import java.util.Calendar;
    > import java.text.SimpleDateFormat;
    > import java.text.ParsePosition;
    >
    > public class DateTest
    > {
    >
    > public DateTest()
    > {
    > }
    >
    > public static void main(String[] args)
    > {
    > String sDate = "30.06.2001";
    > System.out.println( sDate);
    > SimpleDateFormat localFormatter = new SimpleDateFormat("MM.dd.yyyy");
    > ParsePosition pos = new ParsePosition(0);
    > Date myDate = localFormatter.parse(sDate, pos);
    > System.out.println( localFormatter.format(myDate) );
    > }
    > }
    >
    > It produces the following outup :
    > 30.06.2001
    > 06.06.2003
    >
    >
    > Any explanation is welcomed.
    >
    >
    > --
    > Jean-Philippe Forti
    > EIM SA Switzerland
    > jpforti@eim.nospam (replace nospam with ch)
    >
    >




  3. #3
    Jean-Philippe Forti Guest

    Re: Java and dates ?

    So ???
    How could I avoid it ?


    "Paul Clapham" <pclapham@core-mark.com> wrote in message
    news:3adde707$1@news.devx.com...
    > The 6th day of the 30th month of 2001: that's two years later than the

    6th
    > day of the 6th month of 2001.
    >
    > PC2
    >
    > "Jean-Philippe Forti" <jpforti@eim.nospam> wrote in message
    > news:3adda47d$1@news.devx.com...
    > > Could someone tell me why java convert the following date 30.06.2001
    > > (MM.DD.YYYY) in 06.06.2003 ?
    > >
    > > I use the followin code :
    > >
    > > import java.util.Date;
    > > import java.util.Calendar;
    > > import java.text.SimpleDateFormat;
    > > import java.text.ParsePosition;
    > >
    > > public class DateTest
    > > {
    > >
    > > public DateTest()
    > > {
    > > }
    > >
    > > public static void main(String[] args)
    > > {
    > > String sDate = "30.06.2001";
    > > System.out.println( sDate);
    > > SimpleDateFormat localFormatter = new

    SimpleDateFormat("MM.dd.yyyy");
    > > ParsePosition pos = new ParsePosition(0);
    > > Date myDate = localFormatter.parse(sDate, pos);
    > > System.out.println( localFormatter.format(myDate) );
    > > }
    > > }
    > >
    > > It produces the following outup :
    > > 30.06.2001
    > > 06.06.2003
    > >
    > >
    > > Any explanation is welcomed.
    > >
    > >
    > > --
    > > Jean-Philippe Forti
    > > EIM SA Switzerland
    > > jpforti@eim.nospam (replace nospam with ch)
    > >
    > >

    >
    >




  4. #4
    Paul Clapham Guest

    Re: Java and dates ?

    Avoid what? The only other option you have is to make it throw an
    exception. And you would do that by

    localFormatter.setLenient(false);

    PC2

    "Jean-Philippe Forti" <jpforti@eim.nospam> wrote in message
    news:3ade8ce9$1@news.devx.com...
    > So ???
    > How could I avoid it ?
    >
    >
    > "Paul Clapham" <pclapham@core-mark.com> wrote in message
    > news:3adde707$1@news.devx.com...
    > > The 6th day of the 30th month of 2001: that's two years later than the

    > 6th
    > > day of the 6th month of 2001.
    > >
    > > PC2
    > >





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center