java.time.OffsetDateTime.withSecond(int second)方法

java.time.OffsetDateTime.withSecond(int second)方法返回此OffsetDateTime的副本,其中秒数已更改。

声明

以下是java.time.OffsetDateTime.withSecond(int second)方法的声明。

public OffsetDateTime withSecond(int second)

参数

  • second - 在结果中设置的秒数,从059

返回值

基于此日期与所请求年份的OffsetDateTime,不为null

异常

  • DateTimeException - 如果年份值无效。

示例

以下示例显示了java.time.OffsetDateTime.withSecond(int second)方法的用法。

package com.zaixian;

import java.time.OffsetDateTime;

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

      OffsetDateTime date = OffsetDateTime.parse("2017-01-03T10:15:30+01:00");
      OffsetDateTime result = date.withSecond(50);
      System.out.println(result);  
   }
}

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

2017-01-03T10:15:50+01:00

上一篇: java.time.OffsetDateTime类 下一篇: java.time.OffsetTime类