This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Change date for other languages ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Change date for other languages ?" Watch "Change date for other languages ?" New topic
Author

Change date for other languages ?

Edson Cezar
Ranch Hand

Joined: Mar 05, 2011
Posts: 75
    
    1
I have a little doubt, when I execute this simple code, he return for me the String in English, in the case just the Month, but I wanted in portuguese.

Caso someone can help me, thanks a lot.


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I'm sure that SimpleDateFormat must have a setLocale method...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
I don't think it has. The nearest I can find is that if you use System.getProperties you get user.country which corresponds to UK in my case. You can try changing that; of course if I change that to "FR" my computer will spend the next week trying to feed me snails and frogs and saying "pas manger le rosbif" (Don't eat roast beef)

So you will have to remember to change it back afterwards.

There are bound to be other similar properties elsewhere. Somebody else will doubtless know something sensible.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
On another recent thread I noticed the getDateInstance method takes a Locale as a parameter, so that sounds more promising.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Indeed SimpleDateFormat does not have a setLocale method, but it does have a constructor to which you can pass a Locale object:


You can also change the default locale, but not by changing a system property as Campbell suggests. Class Locale has a static setDefault method:

This will not be a persistent setting; it will remain in effect only for the JVM that is currently running your program.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Edson Cezar
Ranch Hand

Joined: Mar 05, 2011
Posts: 75
    
    1
Jesper de Jong wrote:Indeed SimpleDateFormat does not have a setLocale method, but it does have a constructor to which you can pass a Locale object:


You can also change the default locale, but not by changing a system property as Campbell suggests. Class Locale has a static setDefault method:

This will not be a persistent setting; it will remain in effect only for the JVM that is currently running your program.


First, thank for all, I did this example here:



Your output is this :

Sabado, 3 de Setembro de 2011

But I want this output :

3 de Setembro de 2011

I thank anyone who can help me

Edson Cezar
Ranch Hand

Joined: Mar 05, 2011
Posts: 75
    
    1
Thanks all for help me, I did this code, I know this code isn't the best way, but I tried



The output of code is :

Month : 3 de Setembro de 2011 (I needed exactly this)

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Can't you put something like "dd de MMMM de yyyy" into the df constructor? Or DateFormat.LONG instead of FULL?
Edson Cezar
Ranch Hand

Joined: Mar 05, 2011
Posts: 75
    
    1
Campbell Ritchie wrote:Can't you put something like "dd de MMMM de yyyy" into the df constructor? Or DateFormat.LONG instead of FULL?


Thank you,

I think this is the more simple that I can do :



Thank for all
 
Don't get me started about those stupid light bulbs.
 
subject: Change date for other languages ?
 
Similar Threads
Technical Interview Questions
Comparing two dates
Continously updated date field in GridBagLayout does not work
Date Format ,Please help!
Date formatter