SimpleDateFormat problem  
Author Message
Mike Lin





PostPosted: 2004-4-4 9:12:00 Top

java-programmer, SimpleDateFormat problem Hi, I'm beating my head against this with no avail.

Can someone tell me why this fails? The parsed date's getTime() has some
extra highorder bits set.

DateFormat df = new SimpleDateFormat("mm:ss:SSS");

String s = df.format(new Date(500));
assertTrue(df.parse(s).equals(new Date(500)));

Thanks!
 
Filip Larsen





PostPosted: 2004-4-5 0:33:00 Top

java-programmer >> SimpleDateFormat problem Mike Lin wrote

> Can someone tell me why this fails? The parsed date's getTime() has
some
> extra highorder bits set.
>
> DateFormat df = new SimpleDateFormat("mm:ss:SSS");
>
> String s = df.format(new Date(500));
> assertTrue(df.parse(s).equals(new Date(500)));

The parse method expect the time in the string to be expressed in the
local timezone, which for GMT+ zones and the pattern you use will
result in dates before 1970-01-01 00:00:00 UTC and therefore negative
"getTime" values.

Use "df.setTimeZone(TimeZone.getTimeZone("GMT"))" to force df to parse
GMT times.


Regards,
--
Filip Larsen


 
Filip Larsen





PostPosted: 2004-4-5 0:38:00 Top

java-programmer >> SimpleDateFormat problem I wrote

> The parse method expect the time in the string to be
expressed in the
> local timezone, which for GMT+ zones and the pattern you use
will
> result in dates before 1970-01-01 00:00:00 UTC and therefore
negative
> "getTime" values.

I meant GMT- (minus) zones, of course.


--
Filip Larsen


 
 
karkoff





PostPosted: 2004-11-4 19:29:00 Top

java-programmer >> SimpleDateFormat problem 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
 
 
Michael Borgwardt





PostPosted: 2004-11-4 20:02:00 Top

java-programmer >> SimpleDateFormat problem Karl Vernet wrote:
> 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.
 
 
Ann





PostPosted: 2004-11-5 9:30:00 Top

java-programmer >> SimpleDateFormat problem
"Karl Vernet" <email***@***.com> wrote in message
news:email***@***.com...
> 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.

I get
----------
1.4.2
Wed Jan 01 00:00:00 CST 2003
----------
which appears right