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

java.time.OffsetTime.withSecond(int second)方法返回此OffsetTime的副本,并更改了秒钟。

声明

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

public OffsetTime withSecond(int second)

参数

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

返回值

基于此日期的OffsetTime与请求的秒,不为null

异常

  • DateTimeException - 如果秒的值无效。

示例

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

package com.zaixian;

import java.time.OffsetTime;

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

      OffsetTime time = OffsetTime.parse("10:15:30+01:00");
      OffsetTime result = time.withSecond(20);
      System.out.println(result);  
   }
}

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

10:15:20+01:00

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