Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Change date for other languages ?

 
Edson Cezar
Ranch Hand
Posts: 119
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21318
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure that SimpleDateFormat must have a setLocale method...
 
Campbell Ritchie
Sheriff
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15438
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Edson Cezar
Ranch Hand
Posts: 119
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49776
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic