java.time.OffsetDateTime.withSecond(int second)方法返回此OffsetDateTime的副本,其中秒數已更改。
聲明
以下是java.time.OffsetDateTime.withSecond(int second)方法的聲明。
public OffsetDateTime withSecond(int second)
參數
second- 在結果中設置的秒數,從0到59。
返回值
基於此日期與所請求年份的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
