乔达日期时间 - 月份中的天数范围



我像这样使用Joda DateTime:

DateTime dateTime = new DateTime().withDayOfMonth(31).withMonthOfYear(10).withYear(2017);

并得到以下异常:

org.joda.time.IllegalFieldValueException: Value 0 for dayOfMonth must be in the range [1,30]

但我不知道为什么 - 十月总是有 31 天?

日期时间 API 似乎根据输入的月份检查有效天数。因此,如果您将月份放在首位,那么它应该可以正常工作。

    DateTime dateTime = new DateTime().withMonthOfYear(10).withDayOfMonth(31).withYear(2017);

最新更新