如何使用Jodatime获得给定月份的天数? [英] How do I obtain the amount of days of a given month with Jodatime?
本文介绍了如何使用Jodatime获得给定月份的天数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有28天清楚,
每个闰年有29个)。
我可以通过抄送获得这个信息吗?
(当然不是我的意思)
解决方案
如果你有一个 DateTime
对象,表示月中的值,那么这很简单。您从 DateTime
对象中获取 dayOfMonth
属性,并获取属性的最大值。以下是一个示例函数:
public static int daysOfMonth(int year,int month){
DateTime dateTime = new DateTime(年,月,14,12,0,0,000);
return dateTime.dayOfMonth()。getMaximumValue();
}
30 days hath September,
April, June and November,
All the rest have 31,
Excepting February alone
(And that has 28 days clear,
With 29 in each leap year).
Can I obtain this info anagrammatically? (I don't mean the poem, of course)
解决方案
If you have a DateTime
object which represents a value in the month, then it's pretty straightforward. You get the dayOfMonth
property from that DateTime
object and get the maximum value of the property. Here is a sample function:
public static int daysOfMonth(int year, int month) {
DateTime dateTime = new DateTime(year, month, 14, 12, 0, 0, 000);
return dateTime.dayOfMonth().getMaximumValue();
}
这篇关于如何使用Jodatime获得给定月份的天数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文