Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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 Badass: Making Users Awesome this week in the Game Development 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: 3677
    
  17

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: 19947
    
  25

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: 41541
    
  31
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: 3677
    
  17

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

Joined: Oct 13, 2005
Posts: 41541
    
  31
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: 19947
    
  25

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