使用 DateTimeFormatter 了解月份变化#parseLocalDateTime

Understanding Month Change with DateTimeFormatter#parseLocalDateTime

给出以下 DateTimeFormatter

scala> val dateTimeFormatter: DateTimeFormatter = DateTimeFormat.forPattern("yyyy-mm-dd HH:mm:ss.SSS")
dateTimeFormatter: org.joda.time.format.DateTimeFormatter = org.joda.time.format.DateTimeFormatter@163fc8b4

为什么将 "2015-02-05 22:27:36.491" 传递给以下函数会将月份减 1?

scala> dateTimeFormatter.parseLocalDateTime("2015-02-05 22:27:36.491").toDateTime
res5: org.joda.time.DateTime = 2015-01-05T22:27:36.491-05:00

因为格式模式 m 指的是分钟字段。月份字段是 M。您在分钟和月中都使用了小写 m

您应该使用 "yyyy-MM-dd HH:mm:ss.SSS",而不是 "yyyy-mm-dd HH:mm:ss.SSS"