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

x33g5p2x  于2022-02-05 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(191)

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

ZonedDateTime.getYear介绍

[英]Gets the year field.

This method returns the primitive int value for the year.

The year returned by this method is proleptic as per get(YEAR). To obtain the year-of-era, use get(YEAR_OF_ERA.
[中]获取年份字段。
此方法返回该年的原始int值。
根据get(年),此方法返回的年份是proleptic。要获取纪年,请使用get(year_of_era)。

代码示例

代码示例来源:origin: org.assertj/assertj-core

/**
 * Returns true if both datetime are in the same year, false otherwise.
 *
 * @param actual the actual datetime. expected not be null
 * @param other the other datetime. expected not be null
 * @return true if both datetime are in the same year, false otherwise
 */
private static boolean haveSameYear(ZonedDateTime actual, ZonedDateTime other) {
 return actual.getYear() == other.getYear();
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Returns true if both datetime are in the same year, false otherwise.
 *
 * @param actual the actual datetime. expected not be null
 * @param other the other datetime. expected not be null
 * @return true if both datetime are in the same year, false otherwise
 */
private static boolean haveSameYear(ZonedDateTime actual, ZonedDateTime other) {
 return actual.getYear() == other.getYear();
}

代码示例来源:origin: Raysmond/SpringBlog

@GetMapping(value = "posts/archive")
public String archive(Model model) {
  Map<Integer, List<Post>> posts = Maps.newHashMap();
  postService.getArchivePosts().forEach(post -> {
    if (!posts.containsKey(post.getCreatedAt().getYear())) {
      posts.put(post.getCreatedAt().getYear(), Lists.newArrayList());
    }
    posts.get(post.getCreatedAt().getYear()).add(post);
  });
  model.addAttribute("posts", posts);
  return "posts/archive";
}

代码示例来源:origin: blynkkk/blynk-server

private ZonedDateTime adjustToStartDate(ZonedDateTime zonedStartAt, ZonedDateTime zonedNow, ZoneId zoneId) {
  if (durationType == ReportDurationType.CUSTOM) {
    ZonedDateTime zonedStartDate = getZonedFromTs(startTs, zoneId).with(LocalTime.MIN);
    if (zonedStartDate.isAfter(zonedNow)) {
      zonedStartAt = zonedStartAt
          .withDayOfMonth(zonedStartDate.getDayOfMonth())
          .withMonth(zonedStartDate.getMonthValue())
          .withYear(zonedStartDate.getYear());
    }
  }
  return zonedStartAt;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public int getYear() {
  return dt.getYear();
}

代码示例来源:origin: debezium/debezium

private void assertTimestamp(String c4) {
  // '2014-09-08 17:51:04.777'
  // MySQL container is in UTC and the test time is during summer time period
  ZonedDateTime expectedTimestamp = ZonedDateTime.ofInstant(
      LocalDateTime.parse("2014-09-08T17:51:04.780").atZone(ZoneId.of("US/Samoa")).toInstant(),
      ZoneId.systemDefault());
  ZoneId defaultZoneId = ZoneId.systemDefault();
  ZonedDateTime c4DateTime = ZonedDateTime.parse(c4, ZonedTimestamp.FORMATTER).withZoneSameInstant(defaultZoneId);
  assertThat(c4DateTime.getYear()).isEqualTo(expectedTimestamp.getYear());
  assertThat(c4DateTime.getMonth()).isEqualTo(expectedTimestamp.getMonth());
  assertThat(c4DateTime.getDayOfMonth()).isEqualTo(expectedTimestamp.getDayOfMonth());
  assertThat(c4DateTime.getHour()).isEqualTo(expectedTimestamp.getHour());
  assertThat(c4DateTime.getMinute()).isEqualTo(expectedTimestamp.getMinute());
  assertThat(c4DateTime.getSecond()).isEqualTo(expectedTimestamp.getSecond());
  assertThat(c4DateTime.getNano()).isEqualTo(expectedTimestamp.getNano());
  // We're running the connector in the same timezone as the server, so the timezone in the timestamp
  // should match our current offset ...
  LocalDateTime expectedLocalDateTime = LocalDateTime.parse("2014-09-08T17:51:04.780");
  ZoneOffset expectedOffset = defaultZoneId.getRules().getOffset(expectedLocalDateTime);
  assertThat(c4DateTime.getOffset()).isEqualTo(expectedOffset);
}

代码示例来源:origin: benas/random-beans

/**
 * Create a new {@link YearRandomizer}.
 */
public YearRandomizer() {
  yearRandomizer = new IntegerRangeRandomizer(DEFAULT_DATES_RANGE.getMin().getYear(), DEFAULT_DATES_RANGE.getMax().getYear());
}

代码示例来源:origin: benas/random-beans

/**
 * Create a new {@link YearRandomizer}.
 *
 * @param seed initial seed
 */
public YearRandomizer(final long seed) {
  yearRandomizer = new IntegerRangeRandomizer(DEFAULT_DATES_RANGE.getMin().getYear(), DEFAULT_DATES_RANGE.getMax().getYear(), seed);
}

代码示例来源:origin: apache/metron

int currentYear = currentDate.getYear();

代码示例来源:origin: org.assertj/assertj-core-java8

/**
 * Returns true if both datetime are in the same year, false otherwise.
 *
 * @param actual the actual datetime. expected not be null
 * @param other the other datetime. expected not be null
 * @return true if both datetime are in the same year, false otherwise
 */
private static boolean haveSameYear(ZonedDateTime actual, ZonedDateTime other) {
 return actual.getYear() == other.getYear();
}

代码示例来源:origin: mulesoft/mule

private void assertTimeZoneDate(ZonedDateTime openingDate) {
 assertEquals(openingDate.getYear(), YEAR);
 assertEquals(openingDate.getMonthValue(), MONTH);
 assertEquals(openingDate.getDayOfMonth(), DAY);
}

代码示例来源:origin: aws/aws-sdk-java-v2

private String getCopyrightDateRange() {
  int currentYear = ZonedDateTime.now().getYear();
  int copyrightStartYear = currentYear - 5;
  return String.format("%d-%d", copyrightStartYear, currentYear);
}

代码示例来源:origin: aws/aws-sdk-java-v2

private String getCopyrightDateRange() {
    int currentYear = ZonedDateTime.now().getYear();
    int copyrightStartYear = currentYear - 5;
    return String.format("%d-%d", copyrightStartYear, currentYear);
  }
}

代码示例来源:origin: apache/tinkerpop

@Override
public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final ZonedDateTime zonedDateTime) {
  output.writeInt(zonedDateTime.getYear());
  output.writeInt(zonedDateTime.getMonthValue());
  output.writeInt(zonedDateTime.getDayOfMonth());
  output.writeInt(zonedDateTime.getHour());
  output.writeInt(zonedDateTime.getMinute());
  output.writeInt(zonedDateTime.getSecond());
  output.writeInt(zonedDateTime.getNano());
  output.writeString(zonedDateTime.getZone().getId());
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
  public Year convert(Date in, Context context) throws Exception {
    if (in == null) return null;
    return Year.of(in.toInstant().atZone(zoneId).getYear());
  }
}

代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core

public BigDecimal year(ZonedDateTime dateTime) {
  try {
    return BigDecimal.valueOf(dateTime.getYear());
  } catch (Exception e) {
    String message = String.format("year(%s)", dateTime);
    logError(message, e);
    return null;
  }
}

代码示例来源:origin: apache/james-project

@Test
void yearShouldBeParsedWhenFourDigits() {
  ZonedDateTime dateTime = ZonedDateTime.parse("Wed, 28 Jun 2017 04:35:11 -0700", ImapDateTimeFormatter.rfc5322());
  assertThat(dateTime.getYear()).isEqualTo(2017);
}

代码示例来源:origin: apache/james-project

@Test
void yearShouldBeParsedWhenTwoDigitsLesserThanInitialYear() {
  ZonedDateTime dateTime = ZonedDateTime.parse("28 Jun 64 04:35:11 -0700", ImapDateTimeFormatter.rfc5322());
  assertThat(dateTime.getYear()).isEqualTo(2064);
}

代码示例来源:origin: org.apache.james/james-server-util-java8

@Test
public void yearShouldBeParsedWhenTwoDigitsLesserThanInitialYear() {
  ZonedDateTime dateTime = ZonedDateTime.parse("28 Jun 64 04:35:11 -0700", ImapDateTimeFormatter.rfc5322());
  assertThat(dateTime.getYear()).isEqualTo(2064);
}

代码示例来源:origin: dlemmermann/CalendarFX

static DateValue zonedDateTimeToDateValue(ZonedDateTime dt) {
  return new DateTimeValueImpl(
      dt.getYear(), dt.getMonthValue(), dt.getDayOfMonth(),
      dt.getHour(), dt.getMinute(), dt.getSecond());
}

相关文章

ZonedDateTime类方法