
- java.time 軟體包類
- java.time - 首頁
- java.time - 時鐘
- java.time - 時長
- java.time - 即時
- java.time - 本地日期
- java.time - 本地日期時間
- java.time - 本地時間
- java.time - 月日
- java.time - 偏移日期時間
- java.time - 偏移時間
- java.time - 週期
- java.time - 年
- java.time - 年月
- java.time - 分割槽日期時間
- java.time - 時區 ID
- java.time - 時區偏移
- java.time 軟體包列舉
- java.time - 月份
- java.time 有用的資源
- java.time - 討論
java.time.ZoneOffset.ofTotalSeconds() 方法示例
描述
java.time.ZoneOffset.ofTotalSeconds(int totalSeconds) 方法獲取指定總偏移量(以秒為單位)的 ZoneOffset 例項。
宣告
以下是 java.time.ZoneOffset.ofTotalSeconds(int totalSeconds) 方法的宣告。
public static ZoneOffset ofTotalSeconds(int totalSeconds)
引數
totalSeconds − 總時區偏移量(以秒為單位),介於 -64800 到 +64800 之間。
返回值
非 null 的時區偏移量。
異常
DateTimeException − 如果偏移量不在所需範圍內。
示例
以下示例演示了 java.time.ZoneOffset.ofTotalSeconds(int totalSeconds) 方法的使用。
package com.tutorialspoint; import java.time.ZoneOffset; public class ZoneOffsetDemo { public static void main(String[] args) { ZoneOffset zone = ZoneOffset.ofTotalSeconds(3600); System.out.println(zone); } }
讓我們編譯並執行以上程式,將生成以下結果 −
+01:00
廣告