开发者

Internationlization Java

开发者 https://www.devze.com 2023-02-20 06:30 出处:网络
Is there way to overwrite the default values for internat开发者_JAVA百科ionalization? Example if I get the date in EEEE format it will give me Sunday but I want something like Sunnyday.

Is there way to overwrite the default values for internat开发者_JAVA百科ionalization?

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


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消