當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java OffsetTime minusSeconds()用法及代碼示例


Java中的OffsetTime類的minusSeconds()方法返回此OffsetTime的副本,其中減去指定的秒數。

用法:

public OffsetTime minusSeconds(long Seconds)

參數:此方法接受一個要減去的秒數的參數Seconds。可能是負麵的。


返回值:它基於此時間返回一個OffsetTime並減去Seconds,並且它不為null。

以下示例程序旨在說明minusSeconds()方法:

示例1:

// Java program to demonstrate the minusSeconds() method 
  
import java.time.OffsetTime; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
        // Parses the time 
        OffsetTime time = OffsetTime.parse("11:10:10+05:05"); 
  
        // Specified Seconds subtracted 
        System.out.println("After subtraction, time is: " 
                                   + time.minusSeconds(5)); 
    } 
}
輸出:
After subtraction, time is: 11:10:05+05:05

程序2

// Java program to demonstrate the minusSeconds() method 
  
import java.time.OffsetTime; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
        // Parses the time 
        OffsetTime time = OffsetTime.parse("11:10:10+05:05"); 
  
        // Specified Seconds subtracted 
        System.out.println("After subtraction, time is: " 
                                   + time.minusSeconds(-5)); 
    } 
}
輸出:
After subtraction, time is: 11:10:15+05:05

參考: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#minusSeconds-long-



相關用法


注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetTime minusSeconds() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。