Java Instant query() 方法7 Jan 2025 | 1 分钟阅读 Java Instant 类的 query() 方法用于使用指定的查询来查询 Instant。该方法使用指定的查询策略对象。TemporalQuery 对象定义了用于获取结果的逻辑。 语法参数R - 如我们在语法中看到的,有一个 R,它被表示为一个类型参数,指定结果的类型。 query - 它指定要调用的查询。参数不能为空。 返回值它返回查询结果。它可以返回由查询定义的 Null 值。 ExceptionDateTimeException - 如果无法查询(由查询定义) ArithmeticException - 如果发生数值溢出(由查询定义) 示例 1输出 America/Sao_Paulo 示例 2输出 2017-05-01T20:57:09.883Z Nanos 示例 3输出 Local Date is Days |
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 类的 isSupported() 方法用于检查指定的字段或单位是否受支持。isSupported() 方法包含 2 个参数。语法 public boolean isSupported(TemporalField field) public boolean isSupported(TemporalUnit unit) 参数 field - 要检查的字段,null 返回 false。unit - 要...
5 分钟阅读
Java Instant 类的 plusSeconds() 方法用于返回一个副本,其中添加了指定的秒数。此实例是不可变的,不会受到此方法调用的影响。 语法 public Instant plusSeconds(long secondsToAdd) 参数 secondsToAdd? 它指定要添加的秒数。它可以是...
阅读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 类的 plusNanos() 方法用于返回此 Instant 的副本,其中添加了指定的纳秒持续时间。此实例是不可变的,不会受到此方法调用的影响。 语法 public Instant plusNanos(long NanosToAdd) 参数 nanosToAdd ? 它指定要添加的纳秒数。它可以是...
阅读1分钟
Java Instant 类的 hashCode() 方法用于返回此 instant 的哈希码。 语法 public int hashCode() 参数 无参数。 返回值 每个实例的唯一随机整数。 示例 1 import java.time.Instant; public class InstanthashCodeExample1 { public static void main(String[] args) { ...
阅读1分钟
Java Instant 类的 atZone() 方法用于将 Instant 与时区结合以创建 ZonedDateTime。语法 public ZonedDateTime atZone(ZoneId zone) 参数 zone - 要组合的时区,不能为空。返回 从此 Instant 和指定时区形成的 ZoneDateTime,不能为空。异常 DateTimeException - 如果...
阅读 2 分钟
Java Instant 类的 isAfter() 方法用于检查此 Instant 是否在指定的 Instant 之后。语法 public boolean isAfter(Instant otherInstant) 参数 otherInstant - 要与之比较的另一个 Instant,不能为空。返回 True,如果此 Instant 在指定的 Instant 之后。异常 NullPointerException - 如果 otherInstant 为 null。示例...
阅读1分钟
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 类的 plusMillis() 方法用于返回一个 Instant 的副本,该副本添加了指定的毫秒数。此实例是不可变的,并且不受此方法调用的影响。语法 public Instant plusMillis(long millisToAdd) 参数 millisToAdd?它指定要添加的毫秒数。它可以是...
阅读1分钟
我们请求您订阅我们的新闻通讯以获取最新更新。
我们提供所有技术(如 Java 教程、Android、Java 框架)的教程和面试问题
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India