SimpleDateFormat.parse() ignores the number of characters in pattern

后端 未结 5 2004
难免孤独
难免孤独 2020-11-28 16:35

I\'m trying to parse a date String which can have tree different formats. Even though the String should not match the second pattern it somehow does and therefore returns a

5条回答
  •  遥遥无期
    2020-11-28 17:00

    It is documented in the SimpleDateFormat javadoc:

    For formatting, the number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount. For parsing, the number of pattern letters is ignored unless it's needed to separate two adjacent fields.

提交回复
热议问题