jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Get Locale from the System Date" Watch "Get Locale from the System Date" New topic

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: 2904

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.

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

Joined: Oct 14, 2005
Posts: 19973

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?
I agree. Here's the link: http://aspose.com/file-tools
subject: Get Locale from the System Date
It's not a secret anymore!