Java Instant getLong() 方法2025年1月7日 | 阅读 2 分钟 Java Instant 类的 getLong() 方法用于从当前 Instant 获取指定字段的值,返回一个 long 类型的值。 此方法返回指定字段的值。如果由于字段不支持或出于其他原因无法返回该值,则会抛出异常。 语法参数field - 字段的值。 返回字段的值。 异常DateTimeException - 如果无法获取字段的值,或者该值超出了该字段的有效值范围。 UnsupportedTemporalTypeException - 如果字段不受支持或值的范围超过了 int。 ArithmeticException - 如果发生数值溢出。 示例 1输出 输出将如下所示。 0 示例 2输出 The output will be like this. 2018-08-10T06:00:07.269Z NanoOfSecond > 269000000 -- NanoOfDay not supported MicroOfSecond > 269000 -- MicroOfDay not supported MilliOfSecond > 269 -- MilliOfDay not supported -- SecondOfMinute not supported -- SecondOfDay not supported -- MinuteOfHour not supported -- MinuteOfDay not supported -- HourOfAmPm not supported -- ClockHourOfAmPm not supported -- HourOfDay not supported -- ClockHourOfDay not supported -- AmPmOfDay not supported -- DayOfWeek not supported -- AlignedDayOfWeekInMonth not supported -- AlignedDayOfWeekInYear not supported -- DayOfMonth not supported -- DayOfYear not supported -- EpochDay not supported -- AlignedWeekOfMonth not supported -- AlignedWeekOfYear not supported -- MonthOfYear not supported -- ProlepticMonth not supported -- YearOfEra not supported -- Year not supported -- Era not supported InstantSeconds > 1533880807 -- OffsetSeconds not supported |
Java Instant 类的 plusSeconds() 方法用于返回一个副本,其中添加了指定的秒数。此实例是不可变的,不会受到此方法调用的影响。 语法 public Instant plusSeconds(long secondsToAdd) 参数 secondsToAdd? 它指定要添加的秒数。它可以是...
阅读1分钟
Java Instant 类的 isAfter() 方法用于检查此 Instant 是否在指定的 Instant 之后。语法 public boolean isAfter(Instant otherInstant) 参数 otherInstant - 要与之比较的另一个 Instant,不能为空。返回 True,如果此 Instant 在指定的 Instant 之后。异常 NullPointerException - 如果 otherInstant 为 null。示例...
阅读1分钟
Java Instant 类的 minusNanos() 方法用于返回此 Instant 的副本,其中减去了指定的纳秒持续时间。此实例是不可变的,不会受到此方法调用的影响。 语法 public Instant minusNanos(long nanosToSubtract) 参数 nanosToSubtract - 要减去的纳秒数,可以是正数或负数。 返回一个 Instant...
阅读1分钟
Java Instant 类的 minusSeconds () 方法用于返回此 Instant 的副本,并减去指定的秒数。此实例是不可变的,此方法调用不会对其产生影响。语法 public Instant minusSeconds(long secondsToSubtract) 参数 secondsToSubtract - 要减去的秒数,可以是正数或负数。返回 一个 Instant...
阅读1分钟
Java Instant 类的 plusMillis() 方法用于返回一个 Instant 的副本,该副本添加了指定的毫秒数。此实例是不可变的,并且不受此方法调用的影响。语法 public Instant plusMillis(long millisToAdd) 参数 millisToAdd?它指定要添加的毫秒数。它可以是...
阅读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 类的 isBefore() 方法用于检查此 instant 是否早于指定的 instant。 语法 public boolean isBefore(Instant otherInstant) 参数 otherInstant - 要比较的另一个 instant,非空。 返回值 如果此 instant 早于指定的 instant,则返回 True。 异常 NullPointerException - 如果 otherInstant 为 null。 示例...
阅读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 类的 getEpochSecond() 方法用于获取自 Java 纪元 1970-01-01T00:00:00Z 以来的秒数。纪元秒计数是秒的简单递增计数,其中第 0 秒是 1970-01-01T00:00:00Z。返回一天中的纳秒部分...
阅读1分钟
Java Instant 类的 query() 方法用于使用指定的查询来查询 Instant。此方法使用指定的查询策略对象。TemporalQuery 对象定义了用于获取结果的逻辑。语法 public <R> R query(TemporalQuery<R> query) 参数 R - 我们...
阅读 2 分钟
我们请求您订阅我们的新闻通讯以获取最新更新。
我们提供所有技术(如 Java 教程、Android、Java 框架)的教程和面试问题
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India