- java.time 包類
- java.time - Home
- java.time - Clock
- java.time - Duration
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetDateTime
- java.time - Period
- java.time - Year
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time 包列舉
- java.time - Month
- java.time 實用資源
- java.time - 討論
java.time.OffsetDateTime.minusSeconds() 方法示例
描述
java.time.OffsetDateTime.minusSeconds(long seconds) 方法返回一個 OffsetDateTime 實體,其中減去了指定的秒數。
宣告
以下是 java.time.OffsetDateTime.minusSeconds(long seconds) 方法的宣告。
public OffsetDateTime minusSeconds(long seconds)
引數
nanos - 要減去的秒數,可以為負數。
返回值
基於此日期時間且減去了秒數的 OffsetDateTime,不為空。
異常
DateTimeException - 如果結果超出受支援的日期範圍。
示例
以下示例演示了 java.time.OffsetDateTime.minusSeconds(long seconds) 方法的使用。
package com.tutorialspoint;
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.minusSeconds(20));
}
}
讓我們編譯並執行以上程式,以下為該程式產生的結果:
2017-02-03T12:30:10+01:00
廣告