duration java_Java Duration类| minusMillis()方法与示例
duration java
持續(xù)時間類minusMillis()方法 (Duration Class minusMillis() method)
minusMillis() method is available in java.time package.
minusMillis()方法在java.time包中可用。
minusMillis() method is used to subtract the given duration in milliseconds from this Duration and returns the Duration.
minusMillis()方法用于從此Duration中減去給定的持續(xù)時間(以毫秒為單位),并返回Duration。
minusMillis() 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.
minusMillis()方法是一種非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
minusMillis() method may throw an exception at the time of performing subtraction.
minusMillis()方法在執(zhí)行減法時可能會引發(fā)異常。
ArithmeticException: This exception may throw when the calculated result value exceeds the limit.
ArithmeticException :當(dāng)計算結(jié)果值超過限制時,可能引發(fā)此異常。
Syntax:
句法:
public Duration minusMillis(long millis_val);Parameter(s):
參數(shù):
long millis_val – represents the milliseconds to be subtracted from this Duration.
long millis_val –表示要從此Duration中減去的毫秒數(shù)。
Return value:
返回值:
The return type of this method is Duration, it returns the Duration that holds the value subtracted the given milliseconds from this Duration.
此方法的返回類型為Duration ,它返回的Duration保留從該Duration中減去給定毫秒數(shù)的值。
Example:
例:
// Java program to demonstrate the example // of minusMillis(long millis_val) method of Durationimport java.time.*;public class MinusMillisOfDuration {public static void main(String args[]) {long millis = 2;// Instantiates two Duration objectsDuration du1 = Duration.ofMillis(5);Duration du2 = Duration.ofSeconds(2);// Display du1, du2 System.out.println("du1: " + du1);System.out.println("du2: " + du2);System.out.println();// subtracts the given duration// in milliseconds from this Duration du1 // and returns the Duration i.e. here we // are substracting the given 2 milliseconds// from this du1 that holds the value of 5 // millisecondsDuration minus_val = du1.minusMillis(millis);// Display minus_valSystem.out.println("du1.minusMillis(millis): " + minus_val);// subtracts the given duration// in milliseconds from this Duration du2 // and returns the Duration i.e. here we // are substracting the given 2 milliseconds// from this du2 that holds the value of 2// secondsminus_val = du2.minusMillis(millis);// Display minus_valSystem.out.println("du2.minusMillis(millis): " + minus_val);} }Output
輸出量
du1: PT0.005S du2: PT2Sdu1.minusMillis(millis): PT0.003S du2.minusMillis(millis): PT1.998S翻譯自: https://www.includehelp.com/java/duration-minusmillis-method-with-example.aspx
duration java
總結(jié)
以上是生活随笔為你收集整理的duration java_Java Duration类| minusMillis()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mcq 队列_MCQ | 软件工程基础知
- 下一篇: oracle 11g r2版本号,Ora