Locale Time Format Example

Locale Time Format Example


Posted in : Java Posted on : November 24, 2011 at 7:10 PM Comments : [ 0 ]

In this tutorial you will learn about how to find the time format of a Locale.

Locale Time Format Example

In this tutorial you will learn about how to find the time format of a Locale.

Different locale has the different time zone, it may happens the time happening in your locale is not happened in another locale so, it is required to find out the time of a current locale. The example given below demonstrate you only how to find the time format of a locale.

In the example given below to find the Locale's time format I first find out the available locales, created a new date object then set the time formatting style and locale into the getTimeInstance() method of DateFormat, then use the format() method of DateFormat class to format the time using date object.

Example :

package devmanuals.com;

import java.util.Locale;
import java.util.Date;
import java.text.DateFormat;

public class LocaleTimeFormat
{
public static void main(String arr[])
{
Locale loc[] = Locale.getAvailableLocales();
Date date = new Date();
DateFormat df;
System.out.println("\tAvailable Locales \t Time Format \n");
for (int i = 0; i < loc.length; i++)
{
df = DateFormat.getTimeInstance(DateFormat.DEFAULT, loc[i]);
String f = df.format(date);
System.out.println("\t"+loc[i] + "\t\t\t" + f);
}
}
}

Output :

When you will execute the above example you will get the output as follows :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics