This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Help in converting date from string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help in converting date from string" Watch "Help in converting date from string" New topic
Author

Help in converting date from string

Alessandro Camel
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
Hello,
I try to convert a String into milliseconds but it seems that I am using the wrong pattern.




I'm still getting the same ParseException
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3892
    
  18

The problem is probably that the default locale can't make sense of "Mon". You can try constructing your format with Locale.ENGLISH.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20048
    
  30

You can always see at what index of the String the exception occurs by checking the ParseException's error offset:
In this case it fails because German expect "Mo", not "Mon". My default locale has no problems at all.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Alessandro Camel
Ranch Hand

Joined: Jul 03, 2009
Posts: 35
Stephan van Hulst wrote:The problem is probably that the default locale can't make sense of "Mon". You can try constructing your format with Locale.ENGLISH.


You are right!
Using :



everything is working!

Thanks!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43350
    
  32
The German for Monday is Montag, so maybe the problem is Dec, which would be Dez for Dezember in German
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3892
    
  18

Yeah, but I think Alessandro is using Portuguese :P
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43350
    
  32
I could have sworn somebody was using German. Oh yes, it’s Rob. That got me totally confused. Sorry.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20048
    
  30

It was the first supported (as in: it is a static field of Locale), non-English locale I could think of
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help in converting date from string
 
It's not a secret anymore!