- java.time 包类
- java.time - 首页
- java.time - 时钟
- java.time - 持续时间
- java.time - 即时
- java.time - 本地日期
- java.time - 本地日期时间
- java.time - 本地时间
- java.time - 月份天
- java.time - 偏移日期时间
- java.time - 偏移时间
- java.time - 周期
- java.time - 年份
- java.time - 年月
- java.time - 带有时区的日期时间
- java.time - 时区 ID
- java.time - 时区偏移
- java.time 包枚举
- java.time - 月份
- java.time 有用资源
- java.time - 讨论
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
打印页面