Java Instant adjustInto() 方法2025年1月7日 | 阅读 2 分钟 Java Instant 类的 adjustInto() 方法用于调整指定的 Temporal(接口)对象,使其具有此 Instant。 此方法返回一个与输入具有相同可观察类型的 temporal 对象,并将 instant 更改为与此相同。 语法参数temporal - 要调整的目标对象,非空 返回调整后的对象,非空 调整相当于两次使用 Temporal.with(TemporalField, long),将 ChronoField.INSTANT_SECONDS 和 ChronoField.NANO_OF_SECOND 作为字段传递。 在大多数情况下,通过使用 Temporal.with(TemporalAdjuster) 来反转调用模式会更清晰。 异常DateTimeException - 如果无法进行调整 ArithmeticException - 如果发生数值溢出 示例 1输出 The output will be like this. 2014-12-03T10:15:30Z[Asia/New_Delhi] 示例 2输出 2017-03-10T11:10:35.454+05:30[Asia/Calcutta] 2017-02-03T16:07:30+05:30[Asia/Calcutta] 示例 3输出 2017-04-09T10:15:30Z OffsetDateTime > 2017-05-01T15:50:28.538-05:00 > 2017-04-09T05:15:30-05:00 ZonedDateTime > 2017-05-01T15:50:28.540-05:00[Asia/New_Delhi] > 2017-04-09T05:15:30-05:00[Asia/New_Delhi] Instant > 2017-05-01T20:50:28.540Z > 2017-04-09T10:15:30Z 下一个主题PHP Date()/Time() 函数 |
Java Instant 类的 equals() 方法用于检查此 instant 是否等于指定的 instant。 语法 public boolean equals(Object otherInstant) 参数 otherInstant - 另一个 instant,null 返回 false。 返回值 如果 otherInstant 等于此 instant,则返回 True,否则返回 False。 示例 1 import java.time.Instant; public class...
阅读1分钟
Java Instant 类的 isBefore() 方法用于检查此 instant 是否早于指定的 instant。 语法 public boolean isBefore(Instant otherInstant) 参数 otherInstant - 要比较的另一个 instant,非空。 返回值 如果此 instant 早于指定的 instant,则返回 True。 异常 NullPointerException - 如果 otherInstant 为 null。 示例...
阅读1分钟
Java Instant 类的 getNano() 方法用于获取时间线上的特定时刻,从秒的开始算起。 语法 public int getNano(TemporalField field) 参数 无参数。 返回值 秒内的纳秒数,始终为正,永远不超过 999,999,999。 示例 1 import java.time.Instant; public class InstantgetNanoExample1 { ...
阅读1分钟
Java Instant 类的 ofEpochMilli() 方法用于使用自 1970-01-01T00:00:00Z epoch 以来的毫秒数获取 Instant 实例。秒和纳秒从指定的毫秒数中提取。语法 public static Instant ofEpochMilli(long epochMilli) 参数 epochMilli - 自 1970-01-01T00:00:00Z 以来的毫秒数 返回 一个 Instant,不...
阅读1分钟
Java Instant 类的 plusSeconds() 方法用于返回一个副本,其中添加了指定的秒数。此实例是不可变的,不会受到此方法调用的影响。 语法 public Instant plusSeconds(long secondsToAdd) 参数 secondsToAdd? 它指定要添加的秒数。它可以是...
阅读1分钟
Java Instant 类的 atOffset() 方法用于将 Instant 与偏移量结合以创建 OffsetDateTime。语法 public OffsetDateTime atOffset(ZoneOffset offset) 参数 offset - 要组合的偏移量,不能为空。返回 从此 Instant 和指定偏移量形成的 OffsetDateTime,不能为空。异常 DateTimeException - 如果...
阅读 2 分钟
Java Instant 类的 minus() 方法用于返回此 Instant 的副本,并减去指定的量。Instant minus() 方法包含 2 种参数:Java Instant minus(TemporalAmount amountToSubtract) 方法 Java Instant minus(long amountToSubtract, TemporalUnit unit) minus(TemporalAmount amountToSubtract) 方法返回一个 Instant,...
阅读 3 分钟
Java Instant 类的 hashCode() 方法用于返回此 instant 的哈希码。 语法 public int hashCode() 参数 无参数。 返回值 每个实例的唯一随机整数。 示例 1 import java.time.Instant; public class InstanthashCodeExample1 { public static void main(String[] args) { ...
阅读1分钟
Java Instant 类的 now() 方法用于从系统时钟获取当前 Instant。它包含 2 个参数:Java Instant now(Clock clock) 方法 Instant now() 方法将查询系统 UTC 时钟以获取当前 Instant。Instant now(Clock clock) 方法...
阅读 2 分钟
Java Instant 类的 atZone() 方法用于将 Instant 与时区结合以创建 ZonedDateTime。语法 public ZonedDateTime atZone(ZoneId zone) 参数 zone - 要组合的时区,不能为空。返回 从此 Instant 和指定时区形成的 ZoneDateTime,不能为空。异常 DateTimeException - 如果...
阅读 2 分钟
我们请求您订阅我们的新闻通讯以获取最新更新。
我们提供所有技术(如 Java 教程、Android、Java 框架)的教程和面试问题
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India