-
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)
-
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)
>
>
-
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)
> >
> >
>
>
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks