java.time.OffsetDateTime.minusHours(long hoursToSubtract)
方法返回此OffsetDateTime
的副本,並減去指定的小時數。
聲明
以下是java.time.OffsetDateTime.minusHours(long hoursToSubtract)
方法的聲明。
public OffsetDateTime minusHours(long hoursToSubtract)
參數
hoursToSubtract
- 要減去的小時數,可能是負數。
返回值
基於此日期時間的OffsetDateTime
,減去小時數,不能為null
。
異常
DateTimeException
- 如果結果超出支持的日期範圍。
示例
以下示例顯示了java.time.OffsetDateTime.minusHours(long hoursToSubtract)
方法的用法。
package com.zaixian;
import java.time.OffsetDateTime;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
OffsetDateTime date = OffsetDateTime.parse("2017-02-03T12:30:30+01:00");
System.out.println(date.minusHours(2));
}
}
編譯並運行上面的程式,這將產生以下結果 -
2017-02-03T10:30:30+01:00