Java8 DateTimeFormatter am/pm

后端 未结 2 1161
执笔经年
执笔经年 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.

提交回复
热议问题