Locale: getDisplayCountry()
/*
*
The Date for United States:
In FULL is Tuesday, May 9, 2006
In LONG is May 9, 2006
In MEDIUM is May 9, 2006
In SHORT is 5/9/06
The Date for United Kingdom:
In FULL is 09 May 2006
In LONG is 09 May 2006
In MEDIUM is 09-May-2006
In SHORT is 09/05/06
The Date for Germany:
In FULL is Dienstag, 9. Mai 2006
In LONG is 9. Mai 2006
In MEDIUM is 09.05.2006
In SHORT is 09.05.06
The Date for France:
In FULL is mardi 9 mai 2006
In LONG is 9 mai 2006
In MEDIUM is 9 mai 2006
In SHORT is 09/05/06
* */
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
public class MainClass {
public static void main(String[] args) {
Date today = new Date();
Locale[] locales = { Locale.US, Locale.UK, Locale.GERMANY, Locale.FRANCE };
int[] styles = { DateFormat.FULL, DateFormat.LONG, DateFormat.MEDIUM,
DateFormat.SHORT };
DateFormat fmt;
String[] styleText = { "FULL", "LONG", "MEDIUM", "SHORT" };
// Output the date for each local in four styles
for (int i = 0; i < locales.length; i++) {
System.out.println("\nThe Date for " + locales[i].getDisplayCountry()
+ ":");
for (int j = 0; j < styles.length; j++) {
fmt = DateFormat.getDateInstance(styles[j], locales[i]);
System.out.println("\tIn " + styleText[j] + " is " + fmt.format(today));
}
}
}
}
Related examples in the same category