Locale date format
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class Main {
static public void displayDate(Locale currentLocale) {
Date today;
String result;
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("EEE d MMM yy", currentLocale);
today = new Date();
result = formatter.format(today);
System.out.println("Locale: " + currentLocale.toString());
System.out.println("Result: " + result);
}
static public void main(String[] args) {
Locale[] locales = { new Locale("fr", "FR"), new Locale("de", "DE"),
new Locale("en", "US") };
for (int i = 0; i < locales.length; i++) {
displayDate(locales[i]);
}
}
}
Output:
Locale: fr_FR
Result: jeu. 6 sept. 12
Locale: de_DE
Result: Do 6 Sep 12
Locale: en_US
Result: Thu 6 Sep 12
Home
Java Book
Runnable examples
Java Book
Runnable examples
Date Format:
- Default date format
- Full date format
- Long Date Format
- Medium Locale Canada time format
- Short date Format
- Short Time Format
- Pattern date Format
- Format date(a): am/pm marker
- Format date(d): day in number
- Format date(dd): day in two digits number format
- Format date(E):Day of week
- Format date(EEEE): full name of day of week
- Format date format(h):hour in number
- Format date(hh): hour in two digits number
- Format date(H):hour in a day 24 hour format (0-23)
- Format date(HH):hour in a day two digit(0-23)
- Format date(k):hour in a day(1-24)
- Format date(kk):hour in a day(1-24) two digits
- Format date(K):hour in a day (0-11 in AM/PM)
- Format date(KK): hour in a day (00-11)
- Format date(m): minute
- Format data component(mm):minute in two digit(01, 02 etc.)
- Format date(M):month in 1-12
- Format date(MM):month in two digit( 01, 02 etc.)
- Format date(MMM): month in short name(Jan, Feb etc.)
- Format date(MMMM): month in full name(January, February etc.)
- Format date(s): second
- Format date(ss): second in two digit(01, 02 etc.)
- Format date(yy):year in two digit format( 07, 08 etc.)
- Format date(yyyy):year in full four digit(2007, 2008 etc.)
- Format date(z):time zone
- Format date(Z): time zone in offset
- Format date(zzzz): time zone in full description
- Format date:hh:mm:ss a
- Format date:HH.mm.ss
- Format date:HH:mm:ss Z
- Format date(HH:mm:ss:SSS)
- Format date:MM/dd/yy
- Format date:mm-dd-yyyy hh:mm:ss
- Format date:dd-MMM-yy
- format date:dd MMM yyyy hh:mm:ss a
- Format Date:EEEE MMMMM dd yyyy kk:mm:ss
- Format date:E, dd MMM yyyy HH:mm:ss Z
- Format date:YYYYMMDD
- Locale available for date format
- Locale date format
- Locale date time Format
- Locale Canada Default date format
- Locale Canada Default time format
- Locale Canada Full time format
- Locale Canada Long time format
- Date Format pattern string
- Month Name List
- Short Month Name List
- Weekday Name List
- Weekday Short Name List
- Change date format symbols
- Date Format Symbol
- Current default date format
- Format a date using Rfc822 Date Format