- java.time 包類
- java.time - 首頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - 時間段
- java.time - 年
- java.time - 年月
- java.time - ZonedDateTime
- java.time - 區域 ID
- java.time - 時區偏移量
- java.time 包列舉
- java.time - 月份
- java.time 有用資源
- java.time - 討論
java.time.LocalDateTime.plusSeconds() 方法示例
說明
java.time.LocalDateTime.plusSeconds(long seconds) 方法返回添加了指定秒數的此日期時間副本。
宣告
以下是 java.time.LocalDateTime.plusSeconds(long seconds) 方法的宣告。
public LocalDateTime plusSeconds(long seconds)
引數
seconds - 要新增的秒數,可以為負數。
返回值
此日期時間基礎上的、添加了秒數的 LocalDateTime,非空。
異常
DateTimeException - 如果結果超出了支援的日期範圍。
示例
以下示例演示了 java.time.LocalDateTime.plusSeconds(long seconds) 方法的用法。
package com.tutorialspoint;
import java.time.LocalDateTime;
public class LocalDateTimeDemo {
public static void main(String[] args) {
LocalDateTime date = LocalDateTime.parse("2017-02-03T10:15:30");
System.out.println(date.plusSeconds(20));
}
}
讓我們編譯並執行上述程式,這將生成以下結果 -
2017-02-03T10:15:50
廣告