Java date locale format.

Java date locale format.


Posted in : Core Java Posted on : November 29, 2010 at 3:48 PM Comments : [ 0 ]

Java date locale format.

Java date locale format.

In this example, you will see the use of Locale class of java. With the help this example, you can change your date format into another country date format.

Code:

LocaleDateDemo.java
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class LocaleDateDemo {
public static void main(String[] args) {
	Calendar currCalendar = Calendar.getInstance();
	Locale[] localesArray = new Locale[] { 
		Locale.ENGLISH, 
		Locale.GERMAN,
		Locale.UK, 
		Locale.ITALIAN 
		};
	for (Locale locale : localesArray) {
	DateFormat dateFormat = SimpleDateFormat.getDateInstance(
		SimpleDateFormat.MEDIUM, locale);
	System.out.print("Name of locale = " + locale.getDisplayName());
		System.out.print(" date format = "
		+ dateFormat.format(currCalendar.getTime()) + "\n");
	}
     }
}

Output

Name of locale = English date format = Nov 29, 2010
Name of locale = German date format = 29.11.2010
Name of locale = English (United Kingdom) date format = 29-Nov-2010
Name of locale = Italian date format = 29-nov-2010

Download this code.

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics