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.