Question

Is there way to overwrite the default values for internationalization?

Example if I get the date in EEEE format it will give me Sunday but I want something like Sunnyday.

"EEEE, dd MMM, yyyy" gives me Sunday, 27 Mar, 2011

i want "EEEE, dd MMM, yyyy" give me Sunnyday, 27 Mar, 2011

Was it helpful?

Solution

The strings used by DateFormat are defined by an object of class DateFormatSymbols, which has setXXX methods. So you could try this:

 DateFormatSymbols englishSymbols = DateFormatSymbols.getInstance(Locale.ENGLISH);
 DateFormatSymbols mySymbols = (DateFormatSymbols)englishSymbols.clone();
 String[] weekdays = mySymbols.getWeekdays();
 weekdays[Calendar.SUNDAY] = "Sunnyday";
 mySymbols.setWeekdays(weekdays);
 DateFormat f = new SimpleDateFormat("EEEE, dd MMM, yyyy", mySymbols);

 System.out.println(f.format(new Date()));

It shows for me: Sunnyday, 27 Mar, 2011.

OTHER TIPS

You must set locale, this is example for France:

Locale frLocale = new Locale("fr", "FR");
SimpleDateFormat formatter = new SimpleDateFormat("EEE d MMM yy", frLocale);
Date today = new Date();
String output = formatter.format(today);
System.out.println(output);

Output: dimanche 27 mars 11

Or if you want have own names:

String[] monthNames = {"cold January", "warm February" ...};     
Calendar cal = Calendar.getInstance();
String month = monthName[cal.get(Calendar.MONTH)];     
System.out.println("Month name: " + month);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top