int days = Month.FEBRUARY.minLength(); // 28
int days = Month.FEBRUARY.maxLength(); // 29
int days = Month.FEBRUARY.length( boolean_consider_leap_year ); // TRUE → 29, FALSE → 28.
Using the java.time classes, the java.time.Month enum in particular.
int days = Month.FEBRUARY.minLength(); // 28
int days = Month.FEBRUARY.maxLength(); // 29
int days = Month.FEBRUARY.length( boolean_consider_leap_year ); // TRUE → 29, FALSE → 28.
You can get the Month object for a month number, 1-12 meaning January-December.
int monthNumber = Month.FEBRUARY.getValue();
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old date-time classes such as java.util.Date, .Calendar, & java.text.SimpleDateFormat.
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
发布评论
评论(3)
在 Calendar 对象上设置年份和月份,然后使用
getActualMaximum
返回最后一天:Set the year and month on a Calendar object and then use
getActualMaximum
to return the last day:从 Java 8 开始,一个简单的方法是:
Since Java 8, a simple way would be:
java.time.Month
使用 java.time 类,
java.time.Month
枚举。您可以获取月份数字的
Month
对象,1-12 表示一月到十二月。关于 java.time
java.time 框架内置于 Java 8 及更高版本中。这些类取代了麻烦的旧日期时间类,例如 java.util.Date、.Calendar 和 & 。
java.text.SimpleDateFormat
。Joda-Time 项目,现已在 维护模式,建议迁移到 java.time。
要了解更多信息,请参阅 Oracle 教程。并在 Stack Overflow 上搜索许多示例和解释。
许多 java.time 功能都向后移植到 Java 6 和 Java 6。 ThreeTen-Backport 中的 7 并进一步适应 Android 在 ThreeTenABP(请参阅如何使用...)。
ThreeTen-Extra 项目通过附加类扩展了 java.time。该项目是 java.time 未来可能添加的内容的试验场。您可能会在这里找到一些有用的类,例如
Interval
、YearWeek
、YearQuarter
等。java.time.Month
Using the java.time classes, the
java.time.Month
enum in particular.You can get the
Month
object for a month number, 1-12 meaning January-December.About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old date-time classes such as
java.util.Date
,.Calendar
, &java.text.SimpleDateFormat
.The Joda-Time project, now in maintenance mode, advises migration to java.time.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations.
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP (see How to use…).
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as
Interval
,YearWeek
,YearQuarter
, and more.