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



描述

java.time.Instant.plusMillis(long millisToAdd) 方法新增指定毫秒數後返回此即時時間副本。

宣告

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

public Instant plusMillis(long millisToAdd)

引數

millisToAdd − 要新增的毫秒數,為正或負。

返回值

基於此即時時間且添加了指定毫秒數的即時時間,不能為空。

異常

  • DateTimeException − 如果結果超過最大或最小即時時間。

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

示例

以下示例展示了 java.time.Instant.plusMillis(long millisToAdd) 方法的用法。

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.plusMillis(10000);
      System.out.println(result);  
   }
}

接下來編譯並執行上述程式,將生成以下結果 −

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