本文整理了Java中java.time.OffsetDateTime.get()
方法的一些代码示例,展示了OffsetDateTime.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.get()
方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:get
[英]Gets the value of the specified field from this date-time as an int.
This queries this date-time for the value for the specified field. The returned value will always be within the valid range of values for the 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, except NANO_OF_DAY, MICRO_OF_DAY, EPOCH_DAY, EPOCH_MONTH and INSTANT_SECONDS which are too large to fit in an int and throw a DateTimeException. 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.
[中]从该日期时间获取指定字段的int值。
这将查询此日期时间以获取指定字段的值。返回的值将始终在字段的有效值范围内。如果由于字段不受支持或其他原因而无法返回值,则会引发异常。
如果该字段是一个ChronoField,则在此处实现查询。#isSupported(TemporalField)将基于此日期时间返回有效值,但NANO_OF_DAY、MICRO_OF_DAY、EPOCH_DAY、EPOCH_MONTH和INSTANT_SECONDS除外,这些值太大,无法放入整数并引发DateTimeException。所有其他ChronoField实例将抛出DateTimeException。
如果该字段不是ChronoField,则通过调用TemporalField获得该方法的结果。getFrom(临时助理)将此作为参数传递。是否可以获得该值,以及该值代表什么,取决于字段。
代码示例来源:origin: apache/flume
value = clock.instant().atOffset(ZoneOffset.UTC).get(ChronoField.YEAR) + value;
代码示例来源:origin: jneat/mybatis-types
@Override
public void setNonNullParameter(PreparedStatement ps, int i, OffsetDateTime parameter, JdbcType jdbcType) throws SQLException {
// Postgres do not work with offsets > than 15 hours, maybe other DBs too
int offset = parameter.get(ChronoField.OFFSET_SECONDS);
if (Math.abs(offset) > 54000) {
parameter = parameter.withOffsetSameInstant(ZoneOffset.ofHours(offset > 0 ? 15 : -15));
}
ps.setTimestamp(
i,
Timestamp.from(parameter.toInstant()),
GregorianCalendar.from(parameter.toZonedDateTime())
);
}
内容来源于网络,如有侵权,请联系作者删除!