gpt4 book ai didi

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

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

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

Year.getLong介绍

[英]Gets the value of the specified field from this year as a long.

This queries this year 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 year. 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.
[中]获取今年指定字段的值作为long。
这将在今年查询指定字段的值。如果由于字段不受支持或其他原因而无法返回值,则会引发异常。
如果该字段是一个ChronoField,则在此处实现查询。#isSupported(临时字段)将基于今年返回有效值。所有其他ChronoField实例将抛出DateTimeException。
如果该字段不是ChronoField,则通过调用TemporalField获得该方法的结果。getFrom(临时助理)将此作为参数传递。是否可以获得该值,以及该值代表什么,取决于字段。

代码示例

代码示例来源:origin: owlike/genson

private YearTimestampHandler(DateTimeConverterOptions options) {
    super(y -> y.getLong(ChronoField.YEAR), l -> Year.of(l.intValue()), y -> y.getLong(ChronoField.YEAR), l -> Year.of(l.intValue()),
        YEAR_TEMPORAL_FIELDS, Year::now);
  }
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Gets the value of the specified field from this year as an {@code int}.
 * <p>
 * This queries this year 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.
 * <p>
 * If the field is a {@link ChronoField} then the query is implemented here.
 * The {@link #isSupported(TemporalField) supported fields} will return valid
 * values based on this year.
 * All other {@code ChronoField} instances will throw a {@code DateTimeException}.
 * <p>
 * If the field is not a {@code ChronoField}, then the result of this method
 * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
 * passing {@code this} as the argument. Whether the value can be obtained,
 * and what the value represents, is determined by the field.
 *
 * @param field  the field to get, not null
 * @return the value for the field
 * @throws DateTimeException if a value for the field cannot be obtained
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override  // override for Javadoc
public int get(TemporalField field) {
  return range(field).checkValidIntValue(getLong(field), field);
}

代码示例来源:origin: com.github.seratch/java-time-backport

case CENTURIES: return yearsUntil / 100;
case MILLENNIA: return yearsUntil / 1000;
case ERAS: return end.getLong(ERA) - getLong(ERA);

代码示例来源:origin: com.github.seratch/java-time-backport

case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
case YEAR: return Year.of((int) newValue);
case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Year plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    switch ((ChronoUnit) unit) {
      case YEARS: return plusYears(amountToAdd);
      case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
      case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
      case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
      case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
    }
    throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
  }
  return unit.addTo(this, amountToAdd);
}

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