aspose 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: 3647
    
  16

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: 19697
    
  20

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: 38910
    
  23
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: 3647
    
  16

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

Joined: Oct 13, 2005
Posts: 38910
    
  23
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: 19697
    
  20

It was the first supported (as in: it is a static field of Locale), non-English locale I could think of
 
 
subject: Help in converting date from string