• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get Locale from the System Date

 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dariusz Kordonski
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic