congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
Year.from
Code IndexAdd Tabnine to your IDE (free)

How to use
from
method
in
java.time.Year

Best Java code snippets using java.time.Year.from (Showing top 20 results out of 315)

origin: com.thoughtworks.xstream/xstream

final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
final OffsetTime ot = OffsetTime.from(ta);
final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
final OffsetTime ot = OffsetTime.from(ta);
final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
return GregorianCalendar.from(y.atMonthDay(md).atStartOfDay(ZoneId.systemDefault()));
origin: com.github.seratch/java-time-backport

  @Override
  public Year queryFrom(TemporalAccessor temporal) {
    return Year.from(temporal);
  }
};
origin: EvoSuite/evosuite

public static Year from(TemporalAccessor temporal) {
  return Year.from(temporal);
}
origin: org.simpleflatmapper/sfm-converter

  @Override
  public Year convert(Object o, Context context) throws Exception {
    if (o == null) {
      return null;
    }

    if (o instanceof Date) {
      final ZonedDateTime dateTime = Instant.ofEpochMilli(((Date) o).getTime()).atZone(zone);
      return Year.of(dateTime.getYear());
    }

    if (o instanceof Integer || o instanceof Long) {
      return Year.of(((Number)o).intValue());
    }

    if (o instanceof TemporalAccessor) {
      return Year.from((TemporalAccessor) o);
    }

    throw new IllegalArgumentException("Cannot convert " + o + " to Year");
  }
}
origin: arnaudroger/SimpleFlatMapper

  @Override
  public Year convert(Object o, Context context) throws Exception {
    if (o == null) {
      return null;
    }

    if (o instanceof Date) {
      final ZonedDateTime dateTime = Instant.ofEpochMilli(((Date) o).getTime()).atZone(zone);
      return Year.of(dateTime.getYear());
    }

    if (o instanceof Integer || o instanceof Long) {
      return Year.of(((Number)o).intValue());
    }

    if (o instanceof TemporalAccessor) {
      return Year.from((TemporalAccessor) o);
    }

    throw new IllegalArgumentException("Cannot convert " + o + " to Year");
  }
}
origin: org.mycore.mir/mir-module

  private static String getFormatedDateString(String date, DateTimeFormatter formatter) {
    TemporalAccessor ta = formatter.parseBest(date,
      LocalDateTime::from, LocalDate::from, YearMonth::from, Year::from);
    if (ta instanceof LocalDateTime) {
      LocalDateTime ld = LocalDateTime.from(ta);
      return ld.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
    }
    if (ta instanceof LocalDate) {
      LocalDate ld = LocalDate.from(ta);
      return ld.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
    if (ta instanceof YearMonth) {
      YearMonth ld = YearMonth.from(ta);
      return ld.format(DateTimeFormatter.ofPattern("yyyy-MM"));
    }
    if (ta instanceof Year) {
      Year ld = Year.from(ta);
      return ld.format(DateTimeFormatter.ofPattern("yyyy"));
    }
    return date;
  }
}
origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

  public PastDummyEntity(ZonedDateTime dateTime) {
    calendar = GregorianCalendar.from( dateTime );
    date = calendar.getTime();
    instant = dateTime.toInstant();
    localDateTime = dateTime.toLocalDateTime();
    hijrahDate = HijrahDate.from( dateTime );
    japaneseDate = JapaneseDate.from( dateTime );
    localDate = LocalDate.from( dateTime );
    minguoDate = MinguoDate.from( dateTime );
    offsetDateTime = dateTime.toOffsetDateTime();
    thaiBuddhistDate = ThaiBuddhistDate.from( dateTime );
    year = Year.from( dateTime );
    yearMonth = YearMonth.from( dateTime );
    zonedDateTime = dateTime;
  }
}
origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

  public FutureDummyEntity(ZonedDateTime dateTime) {
    calendar = GregorianCalendar.from( dateTime );
    date = calendar.getTime();
    instant = dateTime.toInstant();
    localDateTime = dateTime.toLocalDateTime();
    hijrahDate = HijrahDate.from( dateTime );
    japaneseDate = JapaneseDate.from( dateTime );
    localDate = LocalDate.from( dateTime );
    minguoDate = MinguoDate.from( dateTime );
    offsetDateTime = dateTime.toOffsetDateTime();
    thaiBuddhistDate = ThaiBuddhistDate.from( dateTime );
    year = Year.from( dateTime );
    yearMonth = YearMonth.from( dateTime );
    zonedDateTime = dateTime;
  }
}
origin: zsoltherpai/fluent-jdbc

private static void javaTimeTypes(Map<Class, ObjectMapperRsExtractor<?>> exs) {
  reg(exs, LocalDate.class, (rs, i) -> {
    Date date = rs.getDate(i);
    return date != null ? date.toLocalDate() : null;
  });
  reg(exs, LocalDateTime.class, (rs, i) -> {
    Timestamp stamp = rs.getTimestamp(i);
    return stamp != null ? stamp.toLocalDateTime() : null;
  });
  reg(exs, LocalTime.class, (rs, i) -> {
    Time time = rs.getTime(i);
    return time != null ? time.toLocalTime() : null;
  });
  reg(exs, Year.class, (rs, i) -> {
    Date date = rs.getDate(i);
    return date != null ? Year.from(date.toLocalDate()) : null;
  });
  reg(exs, YearMonth.class, (rs, i) -> {
    Date date = rs.getDate(i);
    return date != null ? YearMonth.from(date.toLocalDate()) : null;
  });
  reg(exs, Instant.class, (rs, i) -> {
    Timestamp stamp = rs.getTimestamp(i);
    return stamp != null ? stamp.toInstant() : null;
  });
}
origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

  public PastDummyEntity(ZonedDateTime dateTime) {
    calendar = GregorianCalendar.from( dateTime );
    date = calendar.getTime();

    instant = dateTime.toInstant();
    localDateTime = dateTime.toLocalDateTime();

    hijrahDate = HijrahDate.from( dateTime );
    japaneseDate = JapaneseDate.from( dateTime );
    localDate = LocalDate.from( dateTime );
    minguoDate = MinguoDate.from( dateTime );
    offsetDateTime = dateTime.toOffsetDateTime();
    thaiBuddhistDate = ThaiBuddhistDate.from( dateTime );
    year = Year.from( dateTime );
    yearMonth = YearMonth.from( dateTime );
    zonedDateTime = dateTime;
  }
}
origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

  public FutureOrPresentDummyEntity(ZonedDateTime dateTime) {
    calendar = GregorianCalendar.from( dateTime );
    date = calendar.getTime();

    instant = dateTime.toInstant();
    localDateTime = dateTime.toLocalDateTime();

    hijrahDate = HijrahDate.from( dateTime );
    japaneseDate = JapaneseDate.from( dateTime );
    localDate = LocalDate.from( dateTime );
    minguoDate = MinguoDate.from( dateTime );
    offsetDateTime = dateTime.toOffsetDateTime();
    thaiBuddhistDate = ThaiBuddhistDate.from( dateTime );
    year = Year.from( dateTime );
    yearMonth = YearMonth.from( dateTime );
    zonedDateTime = dateTime;
  }
}
origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

  public PastOrPresentDummyEntity(ZonedDateTime dateTime) {
    calendar = GregorianCalendar.from( dateTime );
    date = calendar.getTime();

    instant = dateTime.toInstant();
    localDateTime = dateTime.toLocalDateTime();

    hijrahDate = HijrahDate.from( dateTime );
    japaneseDate = JapaneseDate.from( dateTime );
    localDate = LocalDate.from( dateTime );
    minguoDate = MinguoDate.from( dateTime );
    offsetDateTime = dateTime.toOffsetDateTime();
    thaiBuddhistDate = ThaiBuddhistDate.from( dateTime );
    year = Year.from( dateTime );
    yearMonth = YearMonth.from( dateTime );
    zonedDateTime = dateTime;
  }
}
origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

  public PastOrPresentDummyEntity(ZonedDateTime dateTime) {
    calendar = GregorianCalendar.from( dateTime );
    date = calendar.getTime();
    instant = dateTime.toInstant();
    localDateTime = dateTime.toLocalDateTime();
    hijrahDate = HijrahDate.from( dateTime );
    japaneseDate = JapaneseDate.from( dateTime );
    localDate = LocalDate.from( dateTime );
    minguoDate = MinguoDate.from( dateTime );
    offsetDateTime = dateTime.toOffsetDateTime();
    thaiBuddhistDate = ThaiBuddhistDate.from( dateTime );
    year = Year.from( dateTime );
    yearMonth = YearMonth.from( dateTime );
    zonedDateTime = dateTime;
  }
}
origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

  private FutureOrPresentDummyEntity(ZonedDateTime dateTime) {
    calendar = GregorianCalendar.from( dateTime );
    date = calendar.getTime();
    instant = dateTime.toInstant();
    localDateTime = dateTime.toLocalDateTime();
    hijrahDate = HijrahDate.from( dateTime );
    japaneseDate = JapaneseDate.from( dateTime );
    localDate = LocalDate.from( dateTime );
    minguoDate = MinguoDate.from( dateTime );
    offsetDateTime = dateTime.toOffsetDateTime();
    thaiBuddhistDate = ThaiBuddhistDate.from( dateTime );
    year = Year.from( dateTime );
    yearMonth = YearMonth.from( dateTime );
    zonedDateTime = dateTime;
  }
}
origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests

  public FutureDummyEntity(ZonedDateTime dateTime) {
    calendar = GregorianCalendar.from( dateTime );
    date = calendar.getTime();

    instant = dateTime.toInstant();
    localDateTime = dateTime.toLocalDateTime();

    hijrahDate = HijrahDate.from( dateTime );
    japaneseDate = JapaneseDate.from( dateTime );
    localDate = LocalDate.from( dateTime );
    minguoDate = MinguoDate.from( dateTime );
    offsetDateTime = dateTime.toOffsetDateTime();
    thaiBuddhistDate = ThaiBuddhistDate.from( dateTime );
    year = Year.from( dateTime );
    yearMonth = YearMonth.from( dateTime );
    zonedDateTime = dateTime;
  }
}
origin: crawler-commons/crawler-commons

  ldt =  YearMonth.from(ta).atDay(1);
} else if (ta.isSupported(ChronoField.YEAR)) {
  ldt = Year.from(ta).atDay(1);
origin: com.github.seratch/java-time-backport

Year end = Year.from(endExclusive);
if (unit instanceof ChronoUnit) {
  long yearsUntil = ((long) end.year) - year;  // no overflow
origin: x-stream/xstream

final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
final OffsetTime ot = OffsetTime.from(ta);
final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
final OffsetTime ot = OffsetTime.from(ta);
final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
return GregorianCalendar.from(y.atMonthDay(md).atStartOfDay(ZoneId.systemDefault()));
origin: apache/servicemix-bundles

final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
final OffsetTime ot = OffsetTime.from(ta);
final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
final OffsetTime ot = OffsetTime.from(ta);
final Year y = Year.from(ta);
final MonthDay md = MonthDay.from(ta);
return GregorianCalendar.from(y.atMonthDay(md).atStartOfDay(ZoneId.systemDefault()));
origin: arnaudroger/SimpleFlatMapper

@Test
public void testObjectToYear() throws Exception {
  ZoneId zoneId = ZoneId.systemDefault();
  Date now = new Date();
  Year year = Year.from(now.toInstant().atZone(zoneId));
  testObjectToYear(null, null);
  testObjectToYear(year, year);
  testObjectToYear(year.atMonth(6).atEndOfMonth().atTime(1, 0).atZone(zoneId), year);
  testObjectToYear(now, year);
  testObjectToYear(year.getValue(), year);
  try {
    testObjectToYear("a string", year);
    fail();
  } catch (IllegalArgumentException e) {
    // expected
  }
}
java.timeYearfrom

Javadoc

Obtains an instance of Year from a temporal object.

A TemporalAccessor represents some form of date and time information. This factory converts the arbitrary temporal object to an instance of Year.

The conversion extracts the ChronoField#YEAR field. The extraction is only permitted if the temporal object has an ISO chronology, or can be converted to a LocalDate.

This method matches the signature of the functional interface TemporalQueryallowing it to be used in queries via method reference, Year::from.

Popular methods of Year

  • of
    Obtains an instance of Year. This method accepts a year value from the proleptic ISO calendar system
  • getValue
    Gets the year value. The year returned by this method is proleptic as per get(YEAR).
  • parse
    Obtains an instance of Year from a text string using a specific formatter. The text is parsed using
  • now
    Obtains the current year from the system clock in the specified time-zone. This will query the Clock
  • toString
    Outputs this year as a String.
  • atDay
    Combines this year with a day-of-year to create a LocalDate. This returns a LocalDate formed from th
  • isLeap
    Checks if the year is a leap year, according to the ISO proleptic calendar system rules. This method
  • atMonthDay
    Combines this year with a month-day to create a LocalDate. This returns a LocalDate formed from this
  • format
    Outputs this year as a String using the formatter. This year will be passed to the formatter DateTim
  • atMonth
    Combines this year with a month to create a YearMonth. This returns a YearMonth formed from this yea
  • compareTo
    Compares this year to another year. The comparison is based on the value of the year. It is "consist
  • plusYears
    Returns a copy of this year with the specified number of years added. This instance is immutable and
  • compareTo,
  • plusYears,
  • getLong,
  • minusYears,
  • plus,
  • <init>,
  • get,
  • length,
  • range

Popular in Java

  • Start an intent from android
  • setContentView (Activity)
  • compareTo (BigDecimal)
  • onCreateOptionsMenu (Activity)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • 14 Best Plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now