File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 3605
    
  14

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

Joined: Oct 27, 2005
Posts: 19656
    
  18

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
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: 38107
    
  22
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: 3605
    
  14

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

Joined: Oct 13, 2005
Posts: 38107
    
  22
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: 19656
    
  18

It was the first supported (as in: it is a static field of Locale), non-English locale I could think of
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Help in converting date from string
 
Similar Threads
Java Date formatting problem
String to Date...
problems with String to Date Converter
java.text.SimpleDateFormat does not behaves as expected
Can someone please help me parse this date