Locale Date Format Example

Locale Date Format Example


Posted in : Java Posted on : November 24, 2011 at 6:54 PM Comments : [ 0 ]

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

Locale Date Format Example

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

In a different locale the date format is different so when developing a global application it is required to give the functionality in the application to use date according to their locale.

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

Example :

package devmanuals.com;
import java.util.Locale;
import java.util.Date;
import java.text.DateFormat;
public class LocaleDateFormat
{
public static void main(String arr[])
{
Locale loc[]= Locale.getAvailableLocales();
Date date= new Date();
DateFormat df;
System.out.println("\t Available Locales \t Date Format \n");
for(int i=0; i<loc.length; i++)
{
df= DateFormat.getDateInstance(DateFormat.MEDIUM, loc[i]);
String fd= df.format(date);
System.out.println("\t"+loc[i]+"\t\t\t"+fd); 
} 
} 
}

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