java.time.MonthDay.compareTo(MonthDay other)方法将此月-日与另一个月-日进行比较。
声明
以下是java.time.MonthDay.compareTo(MonthDay other)方法的声明。
public int compareTo(MonthDay other)
参数
- other- 比较的其他月份日,不能为- null。
返回值
比较器值,如果小则为负,如果大则为正。
异常
- NullPointerException- 另一个为- null。
示例
以下示例显示了java.time.MonthDay.compareTo(MonthDay other)方法的用法。
package com.zaixian;
import java.time.MonthDay;
public class MonthDayDemo {
   public static void main(String[] args) {
      MonthDay date = MonthDay.parse("--12-30");
      System.out.println(date);  
      MonthDay date1 = MonthDay.parse("--12-20");
      System.out.println(date1);  
      System.out.println(date1.compareTo(date));  
   }
}
编译并运行上面的程序,这将产生以下结果 -
--12-30
--12-20
-10
						上一篇:
								java.time.MonthDay类
												下一篇:
								java.time.OffsetDateTime类
												
						
						
					
					
					