Java calculate days in year, or between two dates

前端 未结 9 1643
慢半拍i
慢半拍i 2021-02-07 04:48

Is there a method in any native Java class to calculate how many days were/will be in a specific year? As in, was it a Leap year (366 days) or a normal year (365 days)?

9条回答
  •  梦谈多话
    2021-02-07 05:12

    The GregorianCalendar standar class has an isLeapyear() method. If all you've got is a year number (say, 2008), then construct a date using this constructor, and then check the isLeapYear() method afterwards.

提交回复
热议问题