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



描述

java.time.Duration.toHours() 方法獲取本持續時間的時數。

宣告

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

public long toHours()

返回的值

持續時間的時數,可以為負數。

示例

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

package com.tutorialspoint;

import java.time.Duration;

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

      Duration duration = Duration.ofDays(2);
      System.out.println(duration.toHours());  
   }
}

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

48
廣告
© . All rights reserved.