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)?
Or do I need to write it myself?
I'm calculating the number of days between two dates, for example, how many days left until my birthday. I want to take into account the February 29 of Leap year. I have it all done except that 29th.
You can use the TimeUnit class. For your specific needs this should do:
Honestly, I don't see where leap years play any role in this calculation, though. Maybe I missed some aspect of your question?
Edit: Stupid me, the leap years magic happens in the
Date.getTime()
. Anyway, you don't have to deal with it this way.You can look at the Wikipedia page for some very nice pseudocode:
I'm sure you can figure out how to implement that logic in Java. :-)