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

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

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

LocalDate.withYear介绍

[英]Returns a copy of this date with the year altered. If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.

This instance is immutable and unaffected by this method call.
[中]返回此日期的副本,并更改年份。如果月份的日期对该年无效,则该日期将更改为该月的最后一个有效日期。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: stackoverflow.com

String input = "12311991";
DateTimeFormatter formatter = DateTimeFormatter.forPattern("MMddyyyy");
LocalDate localDate = LocalDate.parse( input , formatter ); // 1991-12-31
LocalDate differentYear = localDate.withYear( 2013 );  // 2013-12-31

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

/**
 * Returns a copy of this {@code LocalDateTime} with the year altered.
 * The time does not affect the calculation and will be the same in the result.
 * If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param year  the year to set in the result, from MIN_YEAR to MAX_YEAR
 * @return a {@code LocalDateTime} based on this date-time with the requested year, not null
 * @throws DateTimeException if the year value is invalid
 */
public LocalDateTime withYear(int year) {
  return with(date.withYear(year), time);
}

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

/**
 * Returns a copy of this {@code LocalDateTime} with the year altered.
 * The time does not affect the calculation and will be the same in the result.
 * If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param year  the year to set in the result, from MIN_YEAR to MAX_YEAR
 * @return a {@code LocalDateTime} based on this date-time with the requested year, not null
 * @throws DateTimeException if the year value is invalid
 */
public LocalDateTime withYear(int year) {
  return with(date.withYear(year), time);
}

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

/**
 * Returns a copy of this date with the year altered.
 * <p>
 * This method changes the year of the date.
 * If the month-day is invalid for the year, then the previous valid day
 * will be selected instead.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param era  the era to set in the result, not null
 * @param yearOfEra  the year-of-era to set in the returned date
 * @return a {@code JapaneseDate} based on this date with the requested year, never null
 * @throws DateTimeException if {@code year} is invalid
 */
private JapaneseDate withYear(JapaneseEra era, int yearOfEra) {
  int year = JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra);
  return with(isoDate.withYear(year));
}

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

/**
 * Returns a copy of this date with the year altered.
 * <p>
 * This method changes the year of the date.
 * If the month-day is invalid for the year, then the previous valid day
 * will be selected instead.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param era  the era to set in the result, not null
 * @param yearOfEra  the year-of-era to set in the returned date
 * @return a {@code JapaneseDate} based on this date with the requested year, never null
 * @throws DateTimeException if {@code year} is invalid
 */
private JapaneseDate withYear(JapaneseEra era, int yearOfEra) {
  int year = JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra);
  return with(isoDate.withYear(year));
}

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

@Override
public MinguoDate with(TemporalField field, long newValue) {
  if (field instanceof ChronoField) {
    ChronoField f = (ChronoField) field;
    if (getLong(f) == newValue) {
      return this;
    }
    switch (f) {
      case PROLEPTIC_MONTH:
        getChronology().range(f).checkValidValue(newValue, f);
        return plusMonths(newValue - getProlepticMonth());
      case YEAR_OF_ERA:
      case YEAR:
      case ERA: {
        int nvalue = getChronology().range(f).checkValidIntValue(newValue, f);
        switch (f) {
          case YEAR_OF_ERA:
            return with(isoDate.withYear(getProlepticYear() >= 1 ? nvalue + YEARS_DIFFERENCE : (1 - nvalue)  + YEARS_DIFFERENCE));
          case YEAR:
            return with(isoDate.withYear(nvalue + YEARS_DIFFERENCE));
          case ERA:
            return with(isoDate.withYear((1 - getProlepticYear()) + YEARS_DIFFERENCE));
        }
      }
    }
    return with(isoDate.with(field, newValue));
  }
  return field.adjustInto(this, newValue);
}

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

@Override
public MinguoDate with(TemporalField field, long newValue) {
  if (field instanceof ChronoField) {
    ChronoField f = (ChronoField) field;
    if (getLong(f) == newValue) {
      return this;
    }
    switch (f) {
      case PROLEPTIC_MONTH:
        getChronology().range(f).checkValidValue(newValue, f);
        return plusMonths(newValue - getProlepticMonth());
      case YEAR_OF_ERA:
      case YEAR:
      case ERA: {
        int nvalue = getChronology().range(f).checkValidIntValue(newValue, f);
        switch (f) {
          case YEAR_OF_ERA:
            return with(isoDate.withYear(getProlepticYear() >= 1 ? nvalue + YEARS_DIFFERENCE : (1 - nvalue)  + YEARS_DIFFERENCE));
          case YEAR:
            return with(isoDate.withYear(nvalue + YEARS_DIFFERENCE));
          case ERA:
            return with(isoDate.withYear((1 - getProlepticYear()) + YEARS_DIFFERENCE));
        }
      }
    }
    return with(isoDate.with(field, newValue));
  }
  return field.adjustInto(this, newValue);
}

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

@Override
public ThaiBuddhistDate with(TemporalField field, long newValue) {
  if (field instanceof ChronoField) {
    ChronoField f = (ChronoField) field;
    if (getLong(f) == newValue) {
      return this;
    }
    switch (f) {
      case PROLEPTIC_MONTH:
        getChronology().range(f).checkValidValue(newValue, f);
        return plusMonths(newValue - getProlepticMonth());
      case YEAR_OF_ERA:
      case YEAR:
      case ERA: {
        int nvalue = getChronology().range(f).checkValidIntValue(newValue, f);
        switch (f) {
          case YEAR_OF_ERA:
            return with(isoDate.withYear((getProlepticYear() >= 1 ? nvalue : 1 - nvalue)  - YEARS_DIFFERENCE));
          case YEAR:
            return with(isoDate.withYear(nvalue - YEARS_DIFFERENCE));
          case ERA:
            return with(isoDate.withYear((1 - getProlepticYear()) - YEARS_DIFFERENCE));
        }
      }
    }
    return with(isoDate.with(field, newValue));
  }
  return field.adjustInto(this, newValue);
}

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

@Override
public ThaiBuddhistDate with(TemporalField field, long newValue) {
  if (field instanceof ChronoField) {
    ChronoField f = (ChronoField) field;
    if (getLong(f) == newValue) {
      return this;
    }
    switch (f) {
      case PROLEPTIC_MONTH:
        getChronology().range(f).checkValidValue(newValue, f);
        return plusMonths(newValue - getProlepticMonth());
      case YEAR_OF_ERA:
      case YEAR:
      case ERA: {
        int nvalue = getChronology().range(f).checkValidIntValue(newValue, f);
        switch (f) {
          case YEAR_OF_ERA:
            return with(isoDate.withYear((getProlepticYear() >= 1 ? nvalue : 1 - nvalue)  - YEARS_DIFFERENCE));
          case YEAR:
            return with(isoDate.withYear(nvalue - YEARS_DIFFERENCE));
          case ERA:
            return with(isoDate.withYear((1 - getProlepticYear()) - YEARS_DIFFERENCE));
        }
      }
    }
    return with(isoDate.with(field, newValue));
  }
  return field.adjustInto(this, newValue);
}

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

case MONTH_OF_YEAR: return withMonth((int) newValue);
case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH));
case YEAR_OF_ERA: return withYear((int) (year >= 1 ? newValue : 1 - newValue));
case YEAR: return withYear((int) newValue);
case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));

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

case MONTH_OF_YEAR: return withMonth((int) newValue);
case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH));
case YEAR_OF_ERA: return withYear((int) (year >= 1 ? newValue : 1 - newValue));
case YEAR: return withYear((int) newValue);
case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));

相关文章