java.time包中的Duration Class的ofMinutes(long)方法用於獲取1分鍾格式的持續時間。在這種方法中,秒以1分鍾格式(即每分鍾60秒)計算為總秒數。
用法:
public static Duration ofMinutes(long minutes)
參數:此方法接受分鍾參數,即分鍾數。它可以是正數或負數。
返回值:此方法返回以1分鍾格式表示時間的Duration。
異常:如果輸入的分鍾數超過Duration的容量,則此方法將引發ArithmeticException。
以下示例說明了Duration.ofMinutes()方法:
示例1:
// Java code to illustrate ofMinutes() method
import java.time.Duration;
public class GFG {
public static void main(String[] args)
{
// input number of Minutes
long noOfMinutes = 5;
// Duration using ofMinutes() method
Duration duration
= Duration.ofMinutes(noOfMinutes);
System.out.println(duration.getSeconds());
}
}
輸出:
300
示例2:
// Java code to illustrate ofMinutes() method
import java.time.Duration;
public class GFG {
public static void main(String[] args)
{
// input number of Minutes
long noOfMinutes = -214545;
// Duration using ofMinutes() method
Duration duration
= Duration.ofMinutes(noOfMinutes);
System.out.println(duration.getSeconds());
}
}
輸出:
-12872700
參考: https://docs.oracle.com/javase/9/docs/api/java/time/Duration.html#ofMinutes-long-
相關用法
- Java Duration equals(Duration)用法及代碼示例
- Java Duration minus(Duration)用法及代碼示例
- Java Duration dividedBy(Duration)用法及代碼示例
- Java Duration compareTo(Duration)用法及代碼示例
- Java Duration plus(Duration)用法及代碼示例
- Java Duration abs()用法及代碼示例
- Java Duration toDaysPart()用法及代碼示例
- Java Duration negated()用法及代碼示例
- Java Duration get(TemporalUnit)用法及代碼示例
- Java Duration toDays()用法及代碼示例
- Java Duration from(TemporalUnit)用法及代碼示例
- Java Duration toSeconds()用法及代碼示例
- Java Duration isZero()用法及代碼示例
- Java Duration getUnits()用法及代碼示例
- Java Duration hashCode()用法及代碼示例
注:本文由純淨天空篩選整理自Code_r大神的英文原創作品 Duration ofMinutes(long) method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。