Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

urgent...how to get locale on unix

Status
Not open for further replies.

sourabhjha

Programmer
Jan 13, 2002
121
IN
I have a code where i am getting defaultlocale using locale class.On windows it returns me "en_us" but on unix it returns me "en".How do i make it consistent on both the platforms
 
locale -a will list available locales for your UNIX box. locale will show your current locale settings. On my sun box, setting LANG=en_US.UTF-8 produces the results you want. For example:
Code:
import java.util.*;
public class LocaleTest {
  public static void main(String[] args) {
    System.getProperties().list(System.out);
    System.out.println(Locale.getDefault());
    System.out.println(new Date());
  }
}
Produces the following outputs depending on the locale setting:
Code:
LANG=en_GB java LocaleTest
...
en_GB   <-- the locale
Tue Feb 25 10:57:39 GMT 2003

LANG=en_US.UTF-8 java LocaleTest
...
en_US   <-- the locale
Tue Feb 25 10:58:13 GMT 2003
Hope this helps. Cheers, Neil

 
ps: replace thelast line with the following to gate a locale specific date output:
Code:
    System.out.println(new SimpleDateFormat().format(new Date()));
Cheers, Neil :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top