'L' SimpleDateFormat 中的字符模式
我可以尝试在模式中使用“L”字符(http://developer.android.com/reference/ java/text/SimpleDateFormat.html):
SimpleDateFormat sdf2 = new SimpleDateFormat("d LLLL y 'г'. H:mm:ss z", new Locale("ru", "RU"));
但我得到这个异常:
java.lang.IllegalArgumentException: Unknown pattern character - 'L'
有什么想法,为什么会发生?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Android 2.2 及更低版本似乎不支持 L 字符模式。在寻找斯拉夫语言日期格式的解决方案时,我发现了同样的问题(请参阅我对 XtopherSD 答案的评论)。我最终有条件地编码了格式:
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:
当然,我使用 API 级别 16 模拟设备进行开发,一切正常。当我尝试在 API 级别 7 模拟设备上运行它时,我遇到了同样的错误。
SimpleDateFormat 的手册页, http://developer.android.com/reference/java /text/SimpleDateFormat.html,表示“L”对该月份有效。它还说“M”是有效的。
我将 : 更改
为 :
并且它适用于 API 7 和 16。
Of course I was doing development using and API level 16 emulated device, where everything worked fine. When I tried to run it on an API level 7 emulated devices, I got the same error.
The man page for SimpleDateFormat, http://developer.android.com/reference/java/text/SimpleDateFormat.html, says "L" is valid for the month. It also says "M" is valid.
I changed :
to :
and it worked on both API 7 and 16.
我有同样的问题,但是对于“A”字符,在查看 SimpleDateFormat API 后,没有“A”模式字母,只有“a”。当我更改为“a”模式字母时,它可以正常工作。我也没有看到你的“L”模式字母,所以这可能是问题所在。
看看这里
希望这是有帮助。
I have the same problem but with the 'A' character, after having a look on the SimpleDateFormat API, there is no 'A' pattern letter, just 'a'. And it works properly when I changed to 'a' pattern letter. I don't see your 'L' pattern letter as well, so it maybe the problem.
Take a look here
Hope this is helpfull.