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:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionabs()static SecondsintdividedBy(long divisor) booleanstatic Secondslongget(TemporalUnit unit) longgetUnits()inthashCode()booleanbooleanbooleanisZero()minus(long secondsToSubtract) multipliedBy(long multiplicand) negated()static Secondsof(long seconds) static SecondsofDays(long days) static SecondsofHours(long hours) static SecondsofMinutes(long minutes) plus(long secondsToAdd) subtractFrom(Temporal temporal) toHours()toString()
-
Field Details
-
ZERO
-
-
Method Details
-
of
-
ofMinutes
-
ofHours
-
ofDays
-
from
-
between
-
getAmount
public long getAmount() -
isZero
public boolean isZero() -
isNegative
public boolean isNegative() -
isPositive
public boolean isPositive() -
plus
-
plus
-
minus
-
minus
-
multipliedBy
-
dividedBy
-
negated
-
abs
-
toDuration
-
toMinutes
-
toHours
-
get
- Specified by:
getin interfaceTemporalAmount
-
getUnits
- Specified by:
getUnitsin interfaceTemporalAmount
-
addTo
- Specified by:
addToin interfaceTemporalAmount
-
subtractFrom
- Specified by:
subtractFromin interfaceTemporalAmount
-
compareTo
- Specified by:
compareToin interfaceComparable<Seconds>
-
equals
-
hashCode
-
toString
-