java.time.OffsetTime.withSecond() 方法示例



说明

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

声明

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

public OffsetTime withSecond(int second)

public OffsetTime withSecond(int second)

参数

second - 在结果中设置的分秒,从 0 到 59。

返回值

基于该日期的 OffsetTime,带有所请求的秒,不得为 null。

异常

DateTimeException - 如果分秒值无效。

示例

package com.tutorialspoint;

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
打印页面
© . All rights reserved.