Class Seconds

java.lang.Object
cloud.opencode.base.date.extra.Seconds
All Implemented Interfaces:
Serializable, Comparable<Seconds>, TemporalAmount

public final class Seconds extends Object implements TemporalAmount, Comparable<Seconds>, Serializable
Seconds unit class representing a number of seconds 秒数单位类,表示秒数

This class represents a number of seconds, similar to Duration but focused on the seconds unit. It implements TemporalAmount for use with java.time.

此类表示秒数,类似于Duration但专注于秒单位。实现TemporalAmount以与java.time配合使用。

Features | 主要功能:

  • Type-safe seconds representation - 类型安全的秒数表示
  • Arithmetic operations (plus, minus, multiply, divide) - 算术操作(加、减、乘、除)
  • Conversion to Duration, Minutes, Hours - 转换为Duration、Minutes、Hours
  • TemporalAmount implementation for java.time integration - 实现TemporalAmount以集成java.time

Usage Examples | 使用示例:

Seconds s = Seconds.of(30);
Seconds s2 = Seconds.ofMinutes(2);  // 120 seconds
Duration d = s.toDuration();
LocalDateTime dt = LocalDateTime.now().plus(s);

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Overflow-safe: Yes (uses Math.addExact/multiplyExact) - 溢出安全: 是(使用Math.addExact/multiplyExact)
Since:
JDK 25, opencode-base-date V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also: