Java Instant minusSeconds() 方法7 Jan 2025 | 1 分钟阅读 Java Instant 类的 minusSeconds() 方法用于返回此 Instant 的副本,其中减去了指定的秒数持续时间。 此实例是不可变的,不会受到此方法调用的影响。 语法参数secondsToSubtract - 要减去的秒数,可以是正数或负数。 返回一个基于此 Instant 并减去了指定秒数的 Instant,非 null。 异常DateTimeException - 如果结果超出最大或最小 Instant。 ArithmeticException - 如果发生数值溢出。 示例 1输出 输出将如下所示。 2017-02-03T10:37:20Z 示例 2输出 输出将如下所示。 2017-05-01T20:57:36.857Z 2017-05-01T12:37:36.857Z 2017-05-02T05:17:36.857Z |
Java Instant 类的 plusSeconds() 方法用于返回一个副本,其中添加了指定的秒数。此实例是不可变的,不会受到此方法调用的影响。 语法 public Instant plusSeconds(long secondsToAdd) 参数 secondsToAdd? 它指定要添加的秒数。它可以是...
阅读1分钟
Java Instant 类的 get() 方法用于从此 Instant 中获取指定字段的值(以 int 类型)。它为指定字段的值提供了一个即时结果。返回值将始终在有效范围内...
阅读1分钟
Java Instant 类的 ofEpochSecond() 方法用于使用自 1970-01-01T00:00:00Z 纪元以来的秒数来获取 Instant 实例。纳秒字段设置为零。 语法 public static Instant ofEpochSecond(long epochSecond) 参数 epochSecond - 自 1970-01-01T00:00:00Z 以来的秒数 返回一个 Instant,非 null。 异常 DateTimeException -...
阅读1分钟
Java Instant 类的 getNano() 方法用于获取时间线上的特定时刻,从秒的开始算起。 语法 public int getNano(TemporalField field) 参数 无参数。 返回值 秒内的纳秒数,始终为正,永远不超过 999,999,999。 示例 1 import java.time.Instant; public class InstantgetNanoExample1 { ...
阅读1分钟
Java Instant 类的 atOffset() 方法用于将 Instant 与偏移量结合以创建 OffsetDateTime。语法 public OffsetDateTime atOffset(ZoneOffset offset) 参数 offset - 要组合的偏移量,不能为空。返回 从此 Instant 和指定偏移量形成的 OffsetDateTime,不能为空。异常 DateTimeException - 如果...
阅读 2 分钟
Java Instant 类的 atZone() 方法用于将 Instant 与时区结合以创建 ZonedDateTime。语法 public ZonedDateTime atZone(ZoneId zone) 参数 zone - 要组合的时区,不能为空。返回 从此 Instant 和指定时区形成的 ZoneDateTime,不能为空。异常 DateTimeException - 如果...
阅读 2 分钟
Java Instant 类的 minusNanos() 方法用于返回此 Instant 的副本,其中减去了指定的纳秒持续时间。此实例是不可变的,不会受到此方法调用的影响。 语法 public Instant minusNanos(long nanosToSubtract) 参数 nanosToSubtract - 要减去的纳秒数,可以是正数或负数。 返回一个 Instant...
阅读1分钟
Java Instant 类的 plusNanos() 方法用于返回此 Instant 的副本,其中添加了指定的纳秒持续时间。此实例是不可变的,不会受到此方法调用的影响。 语法 public Instant plusNanos(long NanosToAdd) 参数 nanosToAdd ? 它指定要添加的纳秒数。它可以是...
阅读1分钟
Java Instant 类的 compareTo() 方法用于将此 Instant 与指定的 Instant 进行比较。语法 public int compareTo(Instant otherInstant) 参数 otherInstant - 要与之比较的另一个 Instant,不能为空。返回 比较值,如果小于则为负,如果大于则为正。异常 NullPointerException - 如果 otherInstant 为 null。示例 1 import java.time.Instant; import...
阅读1分钟
Java Instant 类的 isAfter() 方法用于检查此 Instant 是否在指定的 Instant 之后。语法 public boolean isAfter(Instant otherInstant) 参数 otherInstant - 要与之比较的另一个 Instant,不能为空。返回 True,如果此 Instant 在指定的 Instant 之后。异常 NullPointerException - 如果 otherInstant 为 null。示例...
阅读1分钟
我们请求您订阅我们的新闻通讯以获取最新更新。
我们提供所有技术(如 Java 教程、Android、Java 框架)的教程和面试问题
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India