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

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

本文整理了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

  1. /**
  2. * Returns true if both OffsetDateTime are in the same year, false otherwise.
  3. *
  4. * @param actual the actual OffsetDateTime. expected not be null
  5. * @param other the other OffsetDateTime. expected not be null
  6. * @return true if both OffsetDateTime are in the same year, false otherwise
  7. */
  8. private static boolean haveSameYear(OffsetDateTime actual, OffsetDateTime other) {
  9. return actual.getYear() == other.getYear();
  10. }

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

  1. /**
  2. * Returns true if both OffsetDateTime are in the same year, false otherwise.
  3. *
  4. * @param actual the actual OffsetDateTime. expected not be null
  5. * @param other the other OffsetDateTime. expected not be null
  6. * @return true if both OffsetDateTime are in the same year, false otherwise
  7. */
  8. private static boolean haveSameYear(OffsetDateTime actual, OffsetDateTime other) {
  9. return actual.getYear() == other.getYear();
  10. }

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

  1. @Test
  2. public void testTransform() {
  3. Map<String, String> map = new HashMap<>();
  4. map.put("dateTime", "2018-02-14T18:00:00.0000000");
  5. map.put("timeZone", "UTC");
  6. CalendarEventModel.CalendarEventTime time =
  7. transformer.apply(map, new TestTransformerContext());
  8. Assert.assertEquals(18, time.getDateTime().getHour());
  9. Assert.assertEquals(2018, time.getDateTime().getYear());
  10. Assert.assertEquals(14, time.getDateTime().getDayOfMonth());
  11. }
  12. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Creates a new Carbon instance from the provided offset date time object.
  3. *
  4. * @param offsetDateTime The offset date time that the Carbon instance should be created from.
  5. * @return a Carbon instance with the provided date and time.
  6. */
  7. public static Carbon createFromOffsetDateTime(OffsetDateTime offsetDateTime) {
  8. return Carbon.create(
  9. offsetDateTime.getYear(),
  10. offsetDateTime.getMonthValue(),
  11. offsetDateTime.getDayOfMonth(),
  12. offsetDateTime.getHour(),
  13. offsetDateTime.getMinute(),
  14. offsetDateTime.getSecond()
  15. );
  16. }

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

  1. @Override
  2. public final void serialize(Writer writer, OffsetDateTime datetime) throws IOException {
  3. super.serialize(writer, datetime);
  4. OutputStream stream = writer.stream;
  5. if (!(datetime.getOffset().equals(ZoneOffset.UTC))) {
  6. stream.write(TagString);
  7. ValueWriter.write(stream, datetime.toString());
  8. }
  9. else {
  10. int year = datetime.getYear();
  11. if (year > 9999 || year < 1) {
  12. stream.write(TagString);
  13. ValueWriter.write(stream, datetime.toString());
  14. }
  15. else {
  16. ValueWriter.writeDate(stream, year, datetime.getMonthValue(), datetime.getDayOfMonth());
  17. ValueWriter.writeTime(stream, datetime.getHour(), datetime.getMinute(), datetime.getSecond(), 0, false, true);
  18. ValueWriter.writeNano(stream, datetime.getNano());
  19. stream.write(TagUTC);
  20. }
  21. }
  22. }
  23. }

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

  1. /**
  2. * Creates a date value.
  3. *
  4. * @param date The date value.
  5. */
  6. private Value(OffsetDateTime date) {
  7. XMLGregorianCalendar xmlGregorianCalendar;
  8. try {
  9. xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar();
  10. xmlGregorianCalendar.setYear(date.getYear());
  11. xmlGregorianCalendar.setMonth(date.getMonth().getValue());
  12. xmlGregorianCalendar.setDay(date.getDayOfMonth());
  13. xmlGregorianCalendar.setTime(date.getHour(), date.getMinute(), date.getSecond()); // date.get(ChronoField.MILLI_OF_SECOND)
  14. xmlGregorianCalendar.setTimezone(date.getOffset().getTotalSeconds() / 60);
  15. } catch (DatatypeConfigurationException e) {
  16. xmlGregorianCalendar = null;
  17. }
  18. this.value = xmlGregorianCalendar;
  19. }

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

  1. @Override
  2. public final void serialize(Writer writer, OffsetDateTime datetime) throws IOException {
  3. super.serialize(writer, datetime);
  4. OutputStream stream = writer.stream;
  5. if (!(datetime.getOffset().equals(ZoneOffset.UTC))) {
  6. stream.write(TagString);
  7. ValueWriter.write(stream, datetime.toString());
  8. }
  9. else {
  10. int year = datetime.getYear();
  11. if (year > 9999 || year < 1) {
  12. stream.write(TagString);
  13. ValueWriter.write(stream, datetime.toString());
  14. }
  15. else {
  16. ValueWriter.writeDate(stream, year, datetime.getMonthValue(), datetime.getDayOfMonth());
  17. ValueWriter.writeTime(stream, datetime.getHour(), datetime.getMinute(), datetime.getSecond(), 0, false, true);
  18. ValueWriter.writeNano(stream, datetime.getNano());
  19. stream.write(TagUTC);
  20. }
  21. }
  22. }
  23. }

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

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

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

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

相关文章