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