Locale DateTime Format Example

Locale DateTime Format Example


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

Locale DateTime Format Example

Locale DateTime Format Example

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

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

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

Example :

package devmanuals.com;

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

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

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