java.time.Duration.isNegative() 方法示例



描述

java.time.Duration.isNegative() 方法檢查此持續時間是否為負數(不包括零)。

宣告

以下是 java.time.Duration.isNegative() 方法的宣告。

public boolean isNegative()

返回值

如果此持續時間的總長度小於零,則返回 true。

示例

以下示例展示了 java.time.Duration.isNegative() 方法的用法。

package com.tutorialspoint;

import java.time.Duration;
import java.time.LocalTime;

public class DurationDemo {
   public static void main(String[] args) {

      Duration duration = Duration.between(LocalTime.NOON,LocalTime.MAX);  
      System.out.println(duration.isNegative());
   }
}

我們編譯並執行以上程式,將會產生以下結果 −

false
廣告
© . All rights reserved.