如何使用Joda-Time获得给定月份内的天数? [英] How do I obtain the number of days within a given month using Joda-Time?

查看:230
本文介绍了如何使用Joda-Time获得给定月份内的天数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)

推荐答案

如果您有 DateTime 对象,该对象代表月份中的值,这非常简单。您从该 DateTime 对象获得 dayOfMonth 属性,并获得该属性的最大值。这是一个示例函数:

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();
}

这篇关于如何使用Joda-Time获得给定月份内的天数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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