java.time.Instant.minusSeconds() 方法示例



描述

java.time.Instant.minusSeconds(long secondsToSubtract) 方法返回此 instant 的副本,其中已減去指定持續時間(以秒為單位)。

宣告

以下是 java.time.Instant.minusSeconds(long secondsToSubtract) 方法的宣告。

public Instant minusSeconds(long secondsToSubtract)

引數

secondsToSubtract − 要減去的秒數,可以是正數或負數。

返回值

基於此 instant 的 Instant,其中已減去指定的秒數,不為 null。

異常

  • DateTimeException − 如果結果超過最大或最小 instant。

  • ArithmeticException − 如果發生數值溢位。

示例

以下示例演示了 java.time.Instant.minusSeconds(long secondsToSubtract) 方法的使用。

package com.tutorialspoint;

import java.time.Instant;

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

      Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");
      Instant result = instant.minusSeconds(10);
      System.out.println(result);   
   }
}

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

2017-02-03T10:37:20Z
廣告
© . All rights reserved.