gpt4 book ai didi

java.time.ZonedDateTime.getLong()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 17:50:40 28 4
gpt4 key购买 nike

本文整理了Java中java.time.ZonedDateTime.getLong()方法的一些代码示例,展示了ZonedDateTime.getLong()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.getLong()方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:getLong

ZonedDateTime.getLong介绍

[英]Gets the value of the specified field from this date-time as a long.

This queries this date-time for the value for the specified field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.

If the field is a ChronoField then the query is implemented here. The #isSupported(TemporalField) will return valid values based on this date-time. All other ChronoField instances will throw a DateTimeException.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.getFrom(TemporalAccessor)passing this as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.
[中]获取指定字段从此日期开始的长时间值。
这将查询此日期时间以获取指定字段的值。如果由于字段不受支持或其他原因而无法返回值,则会引发异常。
如果该字段是一个ChronoField,则在此处实现查询。#isSupported(临时字段)将基于此日期时间返回有效值。所有其他ChronoField实例将抛出DateTimeException。
如果该字段不是ChronoField,则通过调用TemporalField获得该方法的结果。getFrom(临时助理)将此作为参数传递。是否可以获得该值,以及该值代表什么,取决于字段。

代码示例

代码示例来源:origin: stackoverflow.com

ZonedDateTime temporal = ...
long epochSecond = temporal.getLong(INSTANT_SECONDS);
int nanoOfSecond = temporal.get(NANO_OF_SECOND);
Date date = new Date(epochSecond * 1000 + nanoOfSecond / 1000000);

代码示例来源:origin: real-logic/artio

public static long toEpochMillis(final String timestamp)
{
  final LocalDateTime parsedDate = LocalDateTime.parse(timestamp, FORMATTER);
  final ZonedDateTime utc = ZonedDateTime.of(parsedDate, ZoneId.of("UTC"));
  return SECONDS.toMillis(utc.toEpochSecond()) + utc.getLong(MILLI_OF_SECOND);
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com