Viren Pushpanayagam
Viren Pushpanayagam

Reputation: 2497

Internationlization Java

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

Upvotes: 1

Views: 258

Answers (2)

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74750

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.

Upvotes: 3

lukastymo
lukastymo

Reputation: 26799

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);

Upvotes: 1

Related Questions