duration java_Java Duration类| toHours()方法与示例
duration java
Duration Class toHours()方法 (Duration Class toHours() method)
toHours() method is available in java.time package.
toHours()方法在java.time包中可用。
toHours() method is used to convert this Duration into the number of hours.
toHours()方法用于將此“持續時間”轉換為小時數。
toHours() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
toHours()方法是一種非靜態方法,只能通過類對象進行訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
toHours() method does not throw an exception at the time of converting this Duration to hours.
在將此Duration轉換為小時時, toHours()方法不會引發異常。
Syntax:
句法:
public long toHours();Parameter(s):
參數:
None
沒有
Return value:
返回值:
The return type of this method is long, it returns the number of hours exists in this Duration.
此方法的返回類型為long ,它返回此Duration中存在的小時數。
Example:
例:
// Java program to demonstrate the example // of long toHours() method of Durationimport java.time.*;public class ToHoursOfDuration {public static void main(String args[]) {// Instantiates two Duration objectsDuration du1 = Duration.ofMinutes(305);Duration du2 = Duration.parse("P0DT0H60M10S");// Display du1 and du2System.out.println("du1: " + du1);System.out.println("du2: " + du2);// represents this Duration du1 in minutes into// number of hours i.e. 305M 5H:5Mlong to_hours = du1.toHours();// Display to_hoursSystem.out.println("du1.toHours(): " + to_hours);// represent this Duration du2 in minutes into// number of hours i.e. 60M10S = 1H 10S hoursto_hours = du2.toHours();// Display to_hoursSystem.out.println("du2.toHours(): " + to_hours);} }Output
輸出量
du1: PT5H5M du2: PT1H10S du1.toHours(): 5 du2.toHours(): 1翻譯自: https://www.includehelp.com/java/duration-tohours-method-with-example.aspx
duration java
總結
以上是生活随笔為你收集整理的duration java_Java Duration类| toHours()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 随机两位小数数_使用8086微处
- 下一篇: scala 字符串转换数组_如何在Sca