org.threeten.bp.LocalDate.getYear()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(131)

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

LocalDate.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(年份)的预测值。要获取纪年,请使用get(纪年)。

代码示例

代码示例来源:origin: prolificinteractive/material-calendarview

/**
 * Get the year
 *
 * @return the year for this day
 */
public int getYear() {
 return date.getYear();
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override
public void writeToParcel(Parcel dest, int flags) {
 dest.writeInt(date.getYear());
 dest.writeInt(date.getMonthValue());
 dest.writeInt(date.getDayOfMonth());
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override
public String toString() {
 return "CalendarDay{" + date.getYear() + "-" + date.getMonthValue() + "-"
   + date.getDayOfMonth() + "}";
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override
public int hashCode() {
 return hashCode(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override protected void onCreate(final Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_basic_modes);
 ButterKnife.bind(this);
 widget.setOnDateChangedListener(this);
 widget.setShowOtherDates(MaterialCalendarView.SHOW_ALL);
 final LocalDate instance = LocalDate.now();
 widget.setSelectedDate(instance);
 final LocalDate min = LocalDate.of(instance.getYear(), Month.JANUARY, 1);
 final LocalDate max = LocalDate.of(instance.getYear(), Month.DECEMBER, 31);
 widget.state().edit().setMinimumDate(min).setMaximumDate(max).commit();
 widget.addDecorators(
   new MySelectorDecorator(this),
   new HighlightWeekendsDecorator(),
   oneDayDecorator
 );
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override protected void onCreate(final Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_basic);
 ButterKnife.bind(this);
 // Add a decorator to disable prime numbered days
 widget.addDecorator(new PrimeDayDisableDecorator());
 // Add a second decorator that explicitly enables days <= 10. This will work because
 // decorators are applied in order, and the system allows re-enabling
 widget.addDecorator(new EnableOneToTenDecorator());
 final LocalDate calendar = LocalDate.now();
 widget.setSelectedDate(calendar);
 final LocalDate min = LocalDate.of(calendar.getYear(), Month.JANUARY, 1);
 final LocalDate max = LocalDate.of(calendar.getYear() + 1, Month.OCTOBER, 31);
 widget.state().edit()
   .setMinimumDate(min)
   .setMaximumDate(max)
   .commit();
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_basic);
 ButterKnife.bind(this);
 widget.setOnDateChangedListener(this);
 widget.setShowOtherDates(MaterialCalendarView.SHOW_ALL);
 final LocalDate instance = LocalDate.now();
 widget.setSelectedDate(instance);
 final LocalDate min = LocalDate.of(instance.getYear(), Month.JANUARY, 1);
 final LocalDate max = LocalDate.of(instance.getYear(), Month.DECEMBER, 31);
 widget.state().edit().setMinimumDate(min).setMaximumDate(max).commit();
 widget.addDecorators(
   new MySelectorDecorator(this),
   new HighlightWeekendsDecorator(),
   oneDayDecorator
 );
 new ApiSimulator().executeOnExecutor(Executors.newSingleThreadExecutor());
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Reconstitutes this object from a stream.
 *
 * @param stream object input stream
 */
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
  stream.defaultReadObject();
  this.era = JapaneseEra.from(isoDate);
  int yearOffset = this.era.startDate().getYear() - 1;
  this.yearOfEra = isoDate.getYear() - yearOffset;
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Reconstitutes this object from a stream.
 *
 * @param stream object input stream
 */
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
  stream.defaultReadObject();
  this.era = JapaneseEra.from(isoDate);
  int yearOffset = this.era.startDate().getYear() - 1;
  this.yearOfEra = isoDate.getYear() - yearOffset;
}

代码示例来源:origin: org.threeten/threetenbp

@Override
public int prolepticYear(Era era, int yearOfEra) {
  if (era instanceof JapaneseEra == false) {
    throw new ClassCastException("Era must be JapaneseEra");
  }
  JapaneseEra jera = (JapaneseEra) era;
  int isoYear = jera.startDate().getYear() + yearOfEra - 1;
  ValueRange range = ValueRange.of(1, jera.endDate().getYear() - jera.startDate().getYear() + 1);
  range.checkValidValue(yearOfEra, YEAR_OF_ERA);
  return isoYear;
}

代码示例来源:origin: ThreeTen/threetenbp

@Override
public int prolepticYear(Era era, int yearOfEra) {
  if (era instanceof JapaneseEra == false) {
    throw new ClassCastException("Era must be JapaneseEra");
  }
  JapaneseEra jera = (JapaneseEra) era;
  int isoYear = jera.startDate().getYear() + yearOfEra - 1;
  ValueRange range = ValueRange.of(1, jera.endDate().getYear() - jera.startDate().getYear() + 1);
  range.checkValidValue(yearOfEra, YEAR_OF_ERA);
  return isoYear;
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Converts a {@code LocalDate} to a {@code java.sql.Date}.
 *
 * @param date  the local date, not null
 * @return the SQL date, not null
 */
@SuppressWarnings("deprecation")
public static java.sql.Date toSqlDate(LocalDate date) {
  return new java.sql.Date(date.getYear() - 1900, date.getMonthValue() -1, date.getDayOfMonth());
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Converts a {@code LocalDate} to a {@code java.sql.Date}.
 *
 * @param date  the local date, not null
 * @return the SQL date, not null
 */
@SuppressWarnings("deprecation")
public static java.sql.Date toSqlDate(LocalDate date) {
  return new java.sql.Date(date.getYear() - 1900, date.getMonthValue() -1, date.getDayOfMonth());
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Obtains the current year from the specified clock.
 * <p>
 * This will query the specified clock to obtain the current year.
 * Using this method allows the use of an alternate clock for testing.
 * The alternate clock may be introduced using {@link Clock dependency injection}.
 *
 * @param clock  the clock to use, not null
 * @return the current year, not null
 */
public static Year now(Clock clock) {
  final LocalDate now = LocalDate.now(clock);  // called once
  return Year.of(now.getYear());
}

代码示例来源:origin: org.threeten/threetenbp

private int findYear(long epochSecond, ZoneOffset offset) {
  // inline for performance
  long localSecond = epochSecond + offset.getTotalSeconds();
  long localEpochDay = Jdk8Methods.floorDiv(localSecond, 86400);
  return LocalDate.ofEpochDay(localEpochDay).getYear();
}

代码示例来源:origin: ThreeTen/threetenbp

private int findYear(long epochSecond, ZoneOffset offset) {
  // inline for performance
  long localSecond = epochSecond + offset.getTotalSeconds();
  long localEpochDay = Jdk8Methods.floorDiv(localSecond, 86400);
  return LocalDate.ofEpochDay(localEpochDay).getYear();
}

代码示例来源:origin: org.springframework.data/spring-data-cassandra

@Override
  public com.datastax.driver.core.LocalDate convert(LocalDate source) {
    return com.datastax.driver.core.LocalDate.fromYearMonthDay(source.getYear(), source.getMonthValue(),
        source.getDayOfMonth());
  }
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Obtains the current year-month from the specified clock.
 * <p>
 * This will query the specified clock to obtain the current year-month.
 * Using this method allows the use of an alternate clock for testing.
 * The alternate clock may be introduced using {@link Clock dependency injection}.
 *
 * @param clock  the clock to use, not null
 * @return the current year-month, not null
 */
public static YearMonth now(Clock clock) {
  final LocalDate now = LocalDate.now(clock);  // called once
  return YearMonth.of(now.getYear(), now.getMonth());
}

代码示例来源:origin: ThreeTen/threetenbp

private JapaneseDate resolveEYD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle, JapaneseEra era, int yoe) {
  if (resolverStyle == ResolverStyle.LENIENT) {
    int y = era.startDate().getYear() + yoe - 1;
    long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_YEAR), 1);
    return dateYearDay(y, 1).plus(days, DAYS);
  }
  int doy = range(DAY_OF_YEAR).checkValidIntValue(fieldValues.remove(DAY_OF_YEAR), DAY_OF_YEAR);
  return dateYearDay(era, yoe, doy);  // smart is same as strict
}

代码示例来源:origin: org.threeten/threetenbp

private JapaneseDate resolveEYD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle, JapaneseEra era, int yoe) {
  if (resolverStyle == ResolverStyle.LENIENT) {
    int y = era.startDate().getYear() + yoe - 1;
    long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_YEAR), 1);
    return dateYearDay(y, 1).plus(days, DAYS);
  }
  int doy = range(DAY_OF_YEAR).checkValidIntValue(fieldValues.remove(DAY_OF_YEAR), DAY_OF_YEAR);
  return dateYearDay(era, yoe, doy);  // smart is same as strict
}

相关文章