java.time.LocalDateTime.withSecond(int seconds)
方法返回此LocalDateTime
的副本,並更改了秒數。
聲明
以下是java.time.LocalDateTime.withSecond(int seconds)
方法的聲明。
public LocalDateTime withSecond(int seconds)
參數
seconds
- 在結果中設置的秒數,從0到59。
返回值
一個LocalDateTime基於此日期與請求的秒數,而不是null
。
異常
DateTimeException
- 如果秒值無效。
示例
以下示例顯示了java.time.LocalDateTime.withSecond(int seconds)
方法的用法。
package com.zaixian;
import java.time.LocalDateTime;
public class LocalDateTimeDemo {
public static void main(String[] args) {
LocalDateTime date = LocalDateTime.parse("2017-01-03T10:15:30");
LocalDateTime result = date.withSecond(40);
System.out.println(result);
}
}
編譯並運行上面的程式,這將產生以下結果 -
2017-03-03T10:15:40
上一篇:
java.time.LocalDateTime類
下一篇:
java.time.LocalTime類