• Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatting Date from any language into US Locale?  RSS feed

 
ravindra patil
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am facing issue on french language ..

date comes as 12 junie 2012 in french ...but while getting in format of DD/MM/YYYY with locale as US/English i am getting unparseble date error

wel so how to make that date English compatible ?
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it Junie in French? I thought it was juin.
You cannot format a Date, only its display. How are you formatting things? DateFormat? %T tags?
 
ravindra patil
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't remember exactly ...i think you are rite ...

we are storing the values in database in some format like DD/MM/YYYY ect ..
so before storing that values we need to bring into that format .. so need to convert/parse it but if i directly pass that value to parse it throws the un parse bale exception

 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens when you print it from the database at the command line with a SELECT statement?
Can you get it to print a java.sql.Date object from your ResultSet to confirm you have got the Date at all?
Sort those things out before trying the formatting.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravindra patil wrote:date comes as 12 junie 2012 in french ...but while getting in format of DD/MM/YYYY with locale as US/English i am getting unparseble date error

And this surprises you?

wel so how to make that date English compatible ?

Translation. Same as if it was spoken.

Pull it into a date that understands French, and output it in a date that understands English-US (which, by the way, is horrific)

I suspect you won't even need the latter, because once you can get a Java Date, you can write that straight to the database and it won't care what language it came in as.

Winston
 
ravindra patil
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi this is what i am trying to do
input is date in french

String dueDate = (String) requestMap.get("Due Date");
DateFormat df =new SimpleDateFormat("MM/dd/yyyy",Locale.US));
df.parse(dueDate) ;


but getting parser exception
java.text.ParseException: Unparseable date: "23 juin 2012"
i want this date in form of MM/DD/YYY
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the date string contains 23 juin 2012, why are you trying to parse it with a pattern that expects 07/23/2012 ?
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if it's in French, why are you trying to parse it using a US Locale object?

You will need two different Locales, and two different SimpleDateFormat objects. One pair will be for parsing a French date like 23 juin 2012, and the other will be for writing a US date like 06/23/12. Since the formats are different, you need two different SimpleDateFormats to handle them.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:And if it's in French, why are you trying to parse it using a US Locale object?

I was going to say something to this effect until I read the following in the SimpleDateFormat javadoc.
SimpleDateFormat also supports localized date and time pattern strings. In these strings, the pattern letters described above may be replaced with other, locale dependent, pattern letters. SimpleDateFormat does not deal with the localization of text other than the pattern letters; that's up to the client of the class.

It seems to imply that SimpleDateFormat cannot recognise non English month names. I may be wrong on this and don't have time to try it out. Anyone know for certain ?
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravindra patil wrote:DateFormat df =new SimpleDateFormat("MM/dd/yyyy",Locale.US));


Here you are saying "I will give you a String that represents a date, and its format will be like this: "6/23/2012" as they do in the US.
But then you try to have it parse a String with this format: "23 juin 2012".

It is as Mike said: for parsing, you must instantiate the DateFormat with the proper pattern for parsing a date in French. Then you will need another DateFormat to display the date object in US English format.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's true that the JavaDoc seems to say it can't handle something like "juin". However if you try it, I think you will be pleasantly surprised. The JavaDoc is misleading in this case.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:It's true that the JavaDoc seems to say it can't handle something like "juin". However if you try it, I think you will be pleasantly surprised. The JavaDoc is misleading in this case.

Well you've sort of ruined the surprise for me now.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!