Java8 DateTimeFormatter am/pm

后端 未结 2 1160
执笔经年
执笔经年 2020-12-10 11:59

I am trying to parse some dates, but the DateTimeParser seems to disagree with me on what is valid

import java.time.ZonedDateTime
import java.time.format.Dat         


        
相关标签:
2条回答
  • 2020-12-10 12:35

    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.

    0 讨论(0)
  • 2020-12-10 12:48

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

    0 讨论(0)
提交回复
热议问题