File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Get Locale from the System Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Get Locale from the System Date" Watch "Get Locale from the System Date" New topic
Author

Get Locale from the System Date

Sarath Koiloth Ramath
Ranch Hand

Joined: May 07, 2008
Posts: 52
Hi friends,

This is my first post in this forum.

How can i get the locale(country name) from a system date.My intention is
date display must determine from system what the locale is and display date appropriately ?

Thanks in advance


J 4 Java
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Check the DateFormat class , which provides the date instance as per Locale !

find out some more method which also help in you objective !

public TimeZone#getTimeZone()

Gets the time zone.

Returns:
the time zone associated with the calendar of DateFormat.



static Locale#getDefault()
Gets the current value of the default locale for this instance of the Java Virtual Machine.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Dariusz Kordonski
Ranch Hand

Joined: Jul 11, 2008
Posts: 49
If all you need to do is print the date according to the default locale of the system, just use the simplest DateFormat.getInstance() factory method. The DateFormat instance you'll get will use the default Locale... by default you may want to specify the style of the displayed date (short/medium/long/full), though, then you have to use on of the factory methods: getDateInstance or getDateTimeInstance, specifying the chosen format.
Sarath Koiloth Ramath
Ranch Hand

Joined: May 07, 2008
Posts: 52
Thanks for the replies.

I tried the above help.Could not find out the desired result.

I will repeat my problem:

I am creating a desktop application which will be used in different contries.So i want to get the current system timezone(i know how to get the timezone).So using this timezone i need to change the date in my application.

For eg:If i am using in US the it should come like mm/dd/yyyy
if i am using it in india the it should come like dd/mm/yy
It the format depands on the timezone selected by the user.

Thanks in Advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

There isn't a function that maps timezones to standard date formats. So you'll have to find some other way.

Although I believe Dariusz Kordonski has given you the right answer. Have you actually tested your application in different countries to see if it does what you want? If so, and if it doesn't do what you want, what does it do differently?
 
jQuery in Action, 2nd edition
 
subject: Get Locale from the System Date