Java计算一年中的天数 [英] Java calculate days in year

查看:1801
本文介绍了Java计算一年中的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在任何本机Java类中是否有一个方法来计算在特定年份中有多少天?如同,是闰年(366天)还是正常年份(365天)?

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)?

或者我需要自己写吗?

我计算两个日期之间的天数,例如,直到我的生日有多少天。我想考虑闰年的2月29日。

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.

推荐答案

GregorianCalendar standar类有一个 isLeapyear()方法。如果你有一个年份(例如 2008 ),那么使用构造函数,然后检查 isLeapYear() 方法。

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.

这篇关于Java计算一年中的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆