Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'L' character pattern in SimpleDateFormat

I can try to use 'L' character in pattern(http://developer.android.com/reference/java/text/SimpleDateFormat.html):

SimpleDateFormat sdf2 = new SimpleDateFormat("d LLLL y 'г'. H:mm:ss z", new Locale("ru", "RU"));

but i get this exception:

java.lang.IllegalArgumentException: Unknown pattern character - 'L'

Any ideas, why it happens?

like image 631
madton Avatar asked Apr 19 '11 12:04

madton


1 Answers

The L character pattern seems not supported on Android versions 2.2 and below. I found the same problem when looking for a solution for date formats in slavic languages (see my comment to XtopherSD's answer). I ended up coding the format conditionally:

String fmt = Build.VERSION.SDK_INT <= 8 ? "MMMM yyyy" : "LLLL yyyy";
SimpleDateFormat sdfDate = new SimpleDateFormat(fmt);
like image 109
Jose_GD Avatar answered Sep 27 '22 22:09

Jose_GD