Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get czech name of month

I have a problem with get a name of month in my language - Czech.

I want to get name of month as noun, but i always get inflected title. I tried many ways to get name, but all ways return inflected title of month name

For example I want to get name of october in czech "Říjen", but i get always "října".

    Calendar cal=Calendar.getInstance();
    SimpleDateFormat month_date = new SimpleDateFormat("MMMMMMMMM");
    String month_name = month_date.format(cal.getTime());
    DateFormat formatData = new SimpleDateFormat("d.MMMM yyyy H:mm");
    System.out.println(month_name);
    System.out.println(String.format(Locale.getDefault(),"%tB", cal));
    System.out.println(formatData.format(cal.getTime()));

All returns bad format for me. Is there any way to get right name of month? Thank you

like image 385
Vanama Avatar asked Dec 19 '22 22:12

Vanama


2 Answers

You may solved this already, but here is the solution. I made a little research and the reason is the change in java.text.DateFormatSymbols in Java 8 (see compatibility guide).

There is a difference between formatting and standalone forms. Formatting forms: ledna, února, března, etc.; Standalone forms: leden, únor, březen, etc.

Also according to rules of the language the name of month when it stands alone starts with lower character, unless it begins the sentence.

This code will provide you the desired result.

public static void main(String[] args) {
  Calendar cal = Calendar.getInstance();
  Locale loc = new Locale("cs", "CZ"); 
  System.out.println(cal.getDisplayName(Calendar.MONTH, Calendar.LONG_STANDALONE, loc));
}
like image 135
MikeX Avatar answered Dec 22 '22 10:12

MikeX


Using this sample code

public static void main(String[] args) {
    Calendar cal= Calendar.getInstance();
    Locale loc = new Locale("cs", "CZ"); 
    System.out.println(String.format(loc,"%tB", cal));
}

I receive output

?íjen

Which looks like what you want (I explicitly defined your Locale).

like image 29
Jeroen Vannevel Avatar answered Dec 22 '22 10:12

Jeroen Vannevel