| Author |
Change date for other languages ?
|
Edson Cezar
Greenhorn
Joined: Mar 05, 2011
Posts: 21
|
|
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: 16482
|
|
|
I'm sure that SimpleDateFormat must have a setLocale method...
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
|
|
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: 32611
|
|
|
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
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
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
Greenhorn
Joined: Mar 05, 2011
Posts: 21
|
|
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
Greenhorn
Joined: Mar 05, 2011
Posts: 21
|
|
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: 32611
|
|
|
Can't you put something like "dd de MMMM de yyyy" into the df constructor? Or DateFormat.LONG instead of FULL?
|
 |
Edson Cezar
Greenhorn
Joined: Mar 05, 2011
Posts: 21
|
|
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
|
 |
 |
|
|
subject: Change date for other languages ?
|
|
|