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.yiibai;
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