代码之家  ›  专栏  ›  技术社区  ›  quma

Joda DateTime-月份天数范围

  •  -1
  • quma  · 技术社区  · 8 年前

    我使用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]
    

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

    1 回复  |  直到 8 年前
        1
  •  1
  •   Raman Sharma    8 年前

    DateTime API似乎根据输入的月份检查有效天数。所以,如果你把月份放在第一位,那么它应该可以像这样工作。

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