当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java java.time.ZonedDateTime.plusSeconds()用法及代码示例



描述

这个java.time.ZonedDateTime.plusSeconds(long seconds)方法返回此日期时间的副本,并添加指定的秒数。

声明

以下是声明java.time.ZonedDateTime.plusSeconds(long seconds)方法。

public ZonedDateTime plusSeconds(long seconds)

参数

seconds- 要添加的秒数,可能是负数。

返回值

基于此日期时间的 ZonedDateTime 添加秒数,不为空。

异常

DateTimeException- 如果结果超出支持的日期范围。

示例

下面的例子展示了 java.time.ZonedDateTime.plusSeconds(long seconds) 方法的用法。

package com.tutorialspoint;

import java.time.ZonedDateTime;

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

      ZonedDateTime date = ZonedDateTime.parse("2017-03-28T12:25:38.492+05:30[Asia/Calcutta]");
      System.out.println(date.plusSeconds(20));  
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

2017-03-28T12:25:58.492+05:30[Asia/Calcutta]

相关用法


注:本文由纯净天空筛选整理自 java.time.ZonedDateTime.plusSeconds() Method Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。