日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

instant java,java.time.Instant.compareTo()方法

發布時間:2023/12/16 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 instant java,java.time.Instant.compareTo()方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

java.time.Instant.compareTo(Instant otherInstant)方法將此瞬間與指定的瞬間進行比較。

聲明

以下是java.time.Instant.compareTo(Instant otherInstant)方法的聲明。

public int compareTo(Instant otherInstant)

參數

otherInstant – 比較的另一個瞬間,而不是null。

返回值

比較器值,如果更小則為負,如果更大則為正。

異常

NullPointerException – 如果otherInstant為null。

示例

以下示例顯示了java.time.Instant.compareTo(Instant otherInstant)方法的用法。

package com.yiibai; import java.time.Instant; import java.time.OffsetDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.Set; public class InstantDemo { public static void main(String[] args) { Instant instant = Instant.parse("2017-02-03T10:37:30.00Z"); System.out.println("Instant #1: " + instant); Instant instant1 = Instant.parse("2017-03-03T10:37:30.00Z"); System.out.println("Instant #2: " + instant1); int result = instant.compareTo(instant1); System.out.println(result >1 ? "Instant #1 is greater than Instant #2." :"Instant #2 is greater than Instant #1."); } }

編譯并運行上面的程序,這將產生以下結果 –

Instant #1: 2017-02-03T10:37:30Z Instant #2: 2017-03-03T10:37:30Z Instant #2 is greater than Instant #1.

¥ 我要打賞 糾錯/補充 收藏

總結

以上是生活随笔為你收集整理的instant java,java.time.Instant.compareTo()方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。