- 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
广告