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

x33g5p2x  于2022-01-25 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(115)

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

OffsetDateTime.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 OffsetDateTime are in the same year, false otherwise.
 *
 * @param actual the actual OffsetDateTime. expected not be null
 * @param other the other OffsetDateTime. expected not be null
 * @return true if both OffsetDateTime are in the same year, false otherwise
 */
private static boolean haveSameYear(OffsetDateTime actual, OffsetDateTime other) {
 return actual.getYear() == other.getYear();
}

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

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

代码示例来源:origin: google/data-transfer-project

@Test
 public void testTransform() {
  Map<String, String> map = new HashMap<>();
  map.put("dateTime", "2018-02-14T18:00:00.0000000");
  map.put("timeZone", "UTC");
  CalendarEventModel.CalendarEventTime time =
    transformer.apply(map, new TestTransformerContext());

  Assert.assertEquals(18, time.getDateTime().getHour());
  Assert.assertEquals(2018, time.getDateTime().getYear());
  Assert.assertEquals(14, time.getDateTime().getDayOfMonth());
 }
}

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

assertThat(c4DateTime.getYear()).isEqualTo(1970);
assertThat(c4DateTime.getMonth()).isEqualTo(Month.JANUARY);
assertThat(c4DateTime.getDayOfMonth()).isEqualTo(1);

代码示例来源:origin: perfectsense/brightspot-cms

private static String dateSkeleton(Locale locale, long timeMillis) {
  return Instant.now().atOffset(ZoneOffset.UTC).getYear() == Instant.ofEpochMilli(timeMillis).atOffset(ZoneOffset.UTC).getYear()
      ? text(locale, null, SKELETON_DATE_KEY)
      : text(locale, null, SKELETON_DATE_WITH_YEAR_KEY);
}

代码示例来源:origin: lukstei/trading-backtest

private static String toYahooQueryDate(Instant instant, String names) {
    OffsetDateTime time = instant.atOffset(ZoneOffset.UTC);
    String[] strings = names.split("");
    return format("%s=%d&%s=%d&%s=%d", strings[0], time.getMonthValue() - 1, strings[1], time.getDayOfMonth(), strings[2], time.getYear());
  }
}

代码示例来源:origin: kiegroup/optaweb-employee-rostering

public static LocalDate toLocalDate(OffsetDateTime time) {
  return LocalDate.of(time.getYear(), time.getMonthValue(), time.getDayOfMonth());
}

代码示例来源:origin: Netflix/iceberg

static String humanDay(int dayOrdinal) {
 OffsetDateTime day = EPOCH.plusDays(dayOrdinal);
 return String.format("%04d-%02d-%02d",
   day.getYear(), day.getMonth().getValue(), day.getDayOfMonth());
}

代码示例来源:origin: Netflix/iceberg

@Override
 public String read(String reuse) {
  OffsetDateTime day = EPOCH.plusDays(column.nextInteger());
  return format("%04d-%02d-%02d", day.getYear(), day.getMonth().getValue(), day.getDayOfMonth());
 }
}

代码示例来源:origin: Netflix/iceberg

static String humanHour(int hourOrdinal) {
 OffsetDateTime time = EPOCH.plusHours(hourOrdinal);
 return String.format("%04d-%02d-%02d-%02d",
   time.getYear(), time.getMonth().getValue(), time.getDayOfMonth(), time.getHour());
}

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

/**
 * Creates a new Carbon instance from the provided offset date time object.
 *
 * @param offsetDateTime The offset date time that the Carbon instance should be created from.
 * @return a Carbon instance with the provided date and time.
 */
public static Carbon createFromOffsetDateTime(OffsetDateTime offsetDateTime) {
  return Carbon.create(
    offsetDateTime.getYear(),
    offsetDateTime.getMonthValue(),
    offsetDateTime.getDayOfMonth(),
    offsetDateTime.getHour(),
    offsetDateTime.getMinute(),
    offsetDateTime.getSecond()
  );
}

代码示例来源:origin: hprose/hprose-java

@Override
  public final void serialize(Writer writer, OffsetDateTime datetime) throws IOException {
    super.serialize(writer, datetime);
    OutputStream stream = writer.stream;
    if (!(datetime.getOffset().equals(ZoneOffset.UTC))) {
      stream.write(TagString);
      ValueWriter.write(stream, datetime.toString());
    }
    else {
      int year = datetime.getYear();
      if (year > 9999 || year < 1) {
        stream.write(TagString);
        ValueWriter.write(stream, datetime.toString());
      }
      else {
        ValueWriter.writeDate(stream, year, datetime.getMonthValue(), datetime.getDayOfMonth());
        ValueWriter.writeTime(stream, datetime.getHour(), datetime.getMinute(), datetime.getSecond(), 0, false, true);
        ValueWriter.writeNano(stream, datetime.getNano());
        stream.write(TagUTC);
      }
    }
  }
}

代码示例来源:origin: rocks.xmpp/xmpp-extensions-common

/**
 * Creates a date value.
 *
 * @param date The date value.
 */
private Value(OffsetDateTime date) {
  XMLGregorianCalendar xmlGregorianCalendar;
  try {
    xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    xmlGregorianCalendar.setYear(date.getYear());
    xmlGregorianCalendar.setMonth(date.getMonth().getValue());
    xmlGregorianCalendar.setDay(date.getDayOfMonth());
    xmlGregorianCalendar.setTime(date.getHour(), date.getMinute(), date.getSecond()); // date.get(ChronoField.MILLI_OF_SECOND)
    xmlGregorianCalendar.setTimezone(date.getOffset().getTotalSeconds() / 60);
  } catch (DatatypeConfigurationException e) {
    xmlGregorianCalendar = null;
  }
  this.value = xmlGregorianCalendar;
}

代码示例来源:origin: org.hprose/hprose-java

@Override
  public final void serialize(Writer writer, OffsetDateTime datetime) throws IOException {
    super.serialize(writer, datetime);
    OutputStream stream = writer.stream;
    if (!(datetime.getOffset().equals(ZoneOffset.UTC))) {
      stream.write(TagString);
      ValueWriter.write(stream, datetime.toString());
    }
    else {
      int year = datetime.getYear();
      if (year > 9999 || year < 1) {
        stream.write(TagString);
        ValueWriter.write(stream, datetime.toString());
      }
      else {
        ValueWriter.writeDate(stream, year, datetime.getMonthValue(), datetime.getDayOfMonth());
        ValueWriter.writeTime(stream, datetime.getHour(), datetime.getMinute(), datetime.getSecond(), 0, false, true);
        ValueWriter.writeNano(stream, datetime.getNano());
        stream.write(TagUTC);
      }
    }
  }
}

代码示例来源:origin: ngs-doo/dsl-json

public static void serialize(final OffsetDateTime value, final JsonWriter sw) {
  final int year = value.getYear();
  if (year < 0) {
    throw new SerializationException("Negative dates are not supported.");

代码示例来源:origin: io.debezium/debezium-connector-mysql

assertThat(c4DateTime.getYear()).isEqualTo(1970);
assertThat(c4DateTime.getMonth()).isEqualTo(Month.JANUARY);
assertThat(c4DateTime.getDayOfMonth()).isEqualTo(1);

相关文章