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



說明

java.time.Instant.minus(TemporalAmount amountToSubtract) 方法返回當前時間戳減去指定數量的時間戳副本。

宣告

以下是 java.time.Instant.minus(TemporalAmount amountToSubtract) 方法的宣告。

public Instant minus(TemporalAmount amountToSubtract)

public Instant minus(TemporalAmount amountToSubtract)

引數

amountToSubtract - 要減去的時間數量,不能為空。

返回值

基於當前時間戳減去指定數量的時間戳副本,不能為空。

  • 異常

  • DateTimeException - 如果無法進行減法。

ArithmeticException - 如果發生數字溢位。

示例

package com.tutorialspoint;

import java.time.Instant;
import java.time.Duration;

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

      Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");
      Duration duration = Duration.ofHours(5); 
      Instant result = instant.minus(duration);
      System.out.println(result);  
   }
}

線上示例

2017-02-03T05:37:30Z
列印頁面
© . All rights reserved.