java.time.OffsetTime.compareTo() 方法示例



說明

java.time.OffsetTime.compareTo(OffsetTime other) 方法將此 time 與其他 time 比較。

宣告

java.time.OffsetTime.compareTo(OffsetTime other) 方法的宣告如下。

public int compareTo(OffsetTime other)

引數

other - 另一個要比較的 time,非空。

返回值

比較器值,小於 0 表示較小,大於 0 表示較大。

異常

NullPointerException - other 為空。

示例

以下示例演示 java.time.OffsetTime.compareTo(OffsetTime other) 方法的用法。

package com.tutorialspoint;

import java.time.OffsetTime;

public class OffsetTimeDemo {
   public static void main(String[] args) {
      
      OffsetTime time = OffsetTime.parse("12:30:30+01:00");
      System.out.println(time);  
      OffsetTime time1 = OffsetTime.parse("12:35:30+01:00");
      System.out.println(time1);  
      System.out.println(time1.compareTo(time));  
   }
}

讓我們編譯並執行上面的程式,這將產生以下結果 -

12:30:30+01:00
12:35:30+01:00
1
廣告
© . All rights reserved.