且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何比较当日&给定日期和月份的月份Java月

更新时间:2022-05-24 23:05:09

java.time.MonthDay



ThreeTenABP 项目,它是 = nofollow noreferrer> Java时间类内置于Java 8及更高版本中。避免麻烦的旧式旧式日期时间类。

java.time.MonthDay

Use modern date-time classes in the ThreeTenABP project, an Android adaptation of the back-port of the java-time classes built into Java 8 and later. Avoid the troublesome old legacy date-time classes.

这些java.time类包括 MonthDay 类代表一个月和一个月中的某天

These java.time classes include the MonthDay class to represent a month and a day-of-month without a year.

MonthDay md = MonthDay.of( 8 , 15 );

此类已实现 可比较 接口及其 compareTo 方法。还实现了 等于 isBefore isAfter 。因此,工作就完成了。

This class already implements the Comparable interface and its compareTo method. Also implements methods equals, isBefore, and isAfter. So, job done.

确定当前 MonthDay 需要一个时区。在任何给定的时刻,日期都会根据时区

ZoneId z = ZoneId.of( "America/Montreal" );
MonthDay today = MonthDay.now( z );






关于java.time



java.time 框架内置于Java 8及更高版本中。这些类取代了麻烦的旧旧版日期时间类,例如 java.util.Date Calendar ,& SimpleDateFormat


About java.time

The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.

现在处于维护模式的Joda-Time 项目建议迁移到 java.time 类。

The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.

要了解更多信息,请参见 Oracle教程。并在Stack Overflow中搜索许多示例和说明。规范为 JSR 310

To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.

从哪里获取java.time类?

Where to obtain the java.time classes?


  • Java SE 8 SE 9 和后来的


    • 内置。

    • 具有捆绑实现的标准Java API的一部分。

    • Java 9添加了一些次要功能和修复。

    • Java SE 8 and SE 9 and later
      • Built-in.
      • Part of the standard Java API with a bundled implementation.
      • Java 9 adds some minor features and fixes.

      • 许多java.time功能都被反向移植到Java 6& nofollow noreferrer> ThreeTen-Backport

      • Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
      • The ThreeTenABP project adapts ThreeTen-Backport (mentioned above) for Android specifically.
      • See How to use ThreeTenABP….