SimpleDateFormat Problem

K

Karl Vernet

Hi all,

I use SimpleDateFormat in many classes, but I can't make it work with
a very simple format :
--------------------------------------
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ParseDate {

public static void main(String[] args)
{
System.out.println( System.getProperty("java.version") );
SimpleDateFormat dateFormat = new SimpleDateFormat( "dd MMM yyyy" );
ParsePosition pos = new ParsePosition( 0 );
Date theDate = dateFormat.parse( "01 Jan 2003", pos );
System.out.println( theDate.toString() );
}
}
--------------------------------------
it gives a java version of 1.4.2_05 and theDate is null !!!!!!!

Any help would be very appreciated.

Thanke in advance
 
M

Michael Borgwardt

Karl said:
I use SimpleDateFormat in many classes, but I can't make it work with
a very simple format : []
SimpleDateFormat dateFormat = new SimpleDateFormat( "dd MMM yyyy" ); []
it gives a java version of 1.4.2_05 and theDate is null !!!!!!!

It works fine for me in 1.5.0, but I can't imagine a bug in such a basic
functionality in 1.4 either.

Is it perhaps a locale problem? The MMM part of the format is language
dependant and you're using the default locale, which might be different
from mine and the one you're expecting.
 
A

Ann

Karl Vernet said:
Hi all,

I use SimpleDateFormat in many classes, but I can't make it work with
a very simple format :
--------------------------------------
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ParseDate {

public static void main(String[] args)
{
System.out.println( System.getProperty("java.version") );
SimpleDateFormat dateFormat = new SimpleDateFormat( "dd MMM yyyy" );
ParsePosition pos = new ParsePosition( 0 );
Date theDate = dateFormat.parse( "01 Jan 2003", pos );
System.out.println( theDate.toString() );
}
}

I get
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top