Java8 DateTimeFormatter am/pm

蓝咒 提交于 2019-11-28 11:01:56

a expects either PM or AM in upper case. To get a case insensitive formatter you need to build it manually:

DateTimeFormatter fmt = new DateTimeFormatterBuilder()
        .parseCaseInsensitive()
        .appendPattern("EEE MMM dd, yyyy h:mma z")
        .toFormatter(Locale.US);

Note that you will get a new error because the 16th of July is not a Wednesday.

It turns out this solution also resolves trying to parse mixed-case months (e.g., "Jul") using "MMM".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!