java.time.OffsetDateTime.plusSeconds() 方法示例



說明

java.time.OffsetDateTime.plusSeconds(long seconds) 方法返回此日期時間的副本,並新增指定秒數。

宣告

以下是 java.time.OffsetDateTime.plusSeconds(long seconds) 方法的宣告。

public OffsetDateTime plusSeconds(long seconds)

引數

seconds - 要新增的秒數,可以為負數。

返回值

以此日期時間為基礎且已新增秒數的 OffsetDateTime,非空。

異常

DateTimeException - 如果結果超出支援的日期範圍。

示例

以下示例演示了 java.time.OffsetDateTime.plusSeconds(long seconds) 方法的用法。

package com.tutorialspoint;

import java.time.OffsetDateTime;

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

      OffsetDateTime date = OffsetDateTime.parse("2017-02-03T10:15:30+01:00");
      System.out.println(date.plusSeconds(20));  
   }
}

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

2017-02-03T10:15:50+01:00
廣告
© . All rights reserved.