java.time.OffsetTime.withSecond(int second)
方法返回此OffsetTime
的副本,並更改了秒鐘。
聲明
以下是java.time.OffsetTime.withSecond(int second)
方法的聲明。
public OffsetTime withSecond(int second)
參數
second
- 在結果中設置的秒數,從0
到59
。
返回值
基於此日期的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類