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
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));
}
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With