java.time.OffsetDateTime.plusHours(long hours)
方法返回此日期时间的副本,并添加指定的小时数。
声明
以下是java.time.OffsetDateTime.plusHours(long hours)
方法的声明。
public OffsetDateTime plusHours(long hours)
参数
hours
- 添加的小时数,可能是负数。
返回值
基于此日期时间添加小时数的OffsetDateTime
,不为null
。
异常
DateTimeException
- 如果结果超出支持的日期范围。
示例
以下示例显示了java.time.OffsetDateTime.plusHours(long hours)
方法的用法。
package com.zaixian;
import java.time.OffsetDateTime;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
OffsetDateTime date = OffsetDateTime.parse("2017-02-03T10:15:30+01:00");
System.out.println(date.plusHours(2));
}
}
编译并运行上面的程序,这将产生以下结果 -
2017-02-03T12:15:30+01:00