Sample L character in SimpleDateFormat

I can try using the "L" character in the template ( 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 this is happening?

+6
source share
3 answers

The character L does not seem to be supported on versions of Android 2.2 and below. I found the same problem when looking for a solution for date formats in Slavic languages ​​(see My comment on XtopherSD answer). I ended up coding the format conditionally:

 String fmt = Build.VERSION.SDK_INT <= 8 ? "MMMM yyyy" : "LLLL yyyy"; SimpleDateFormat sdfDate = new SimpleDateFormat(fmt); 
+7
source

Of course, I was developing using an emulated device of level 16 of the API, where everything worked fine. When I tried to run it on emulated devices of API level 7, I got the same error.

The man page for SimpleDateFormat, http://developer.android.com/reference/java/text/SimpleDateFormat.html , says that "L" is valid for a month. He also says that "M" is valid.

I changed:

 private static SimpleDateFormat sdf_myDate = new SimpleDateFormat("LLLL d yyyy HHmm", Locale.US); 

to:

 private static SimpleDateFormat sdf_myDate= new SimpleDateFormat("MMMM d yyyy HHmm", Locale.US); 

and it worked on both API 7 and 16.

+2
source

I have the same problem, but with the symbol "A", after viewing the SimpleDateFormat API, there is no letter of the template "A", just "a". And it works correctly when I switched to the letter "a". I also do not see your letter "L", so this may be a problem.

Look at here

Hope this is helpful.

0
source

Source: https://habr.com/ru/post/886235/


All Articles