gpt4 book ai didi

java.time.YearMonth.with()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 00:10:40 29 4
gpt4 key购买 nike

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

YearMonth.with介绍

[英]Returns a copy of this year-month with the new year and month, checking to see if a new object is in fact required.
[中]返回包含新年和月份的本月副本,检查是否确实需要新对象。

代码示例

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Returns a copy of this {@code YearMonth} with the month-of-year altered.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param month  the month-of-year to set in the returned year-month, from 1 (January) to 12 (December)
 * @return a {@code YearMonth} based on this year-month with the requested month, not null
 * @throws DateTimeException if the month-of-year value is invalid
 */
public YearMonth withMonth(int month) {
  MONTH_OF_YEAR.checkValidValue(month);
  return with(year, month);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Returns a copy of this {@code YearMonth} with the year altered.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param year  the year to set in the returned year-month, from MIN_YEAR to MAX_YEAR
 * @return a {@code YearMonth} based on this year-month with the requested year, not null
 * @throws DateTimeException if the year value is invalid
 */
public YearMonth withYear(int year) {
  YEAR.checkValidValue(year);
  return with(year, month);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Returns a copy of this year-month with the specified period in years added.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param yearsToAdd  the years to add, may be negative
 * @return a {@code YearMonth} based on this year-month with the years added, not null
 * @throws DateTimeException if the result exceeds the supported range
 */
public YearMonth plusYears(long yearsToAdd) {
  if (yearsToAdd == 0) {
    return this;
  }
  int newYear = YEAR.checkValidIntValue(year + yearsToAdd);  // safe overflow
  return with(newYear, month);
}

代码示例来源:origin: sakaiproject/sakai

YearMonth jan = currentYearMonth.with(Month.JANUARY);
YearMonth feb = currentYearMonth.with(Month.FEBRUARY);
YearMonth mar = currentYearMonth.with(Month.MARCH);
YearMonth apr = currentYearMonth.with(Month.APRIL);
YearMonth may = currentYearMonth.with(Month.MAY);
YearMonth jun = currentYearMonth.with(Month.JUNE);
YearMonth jul = currentYearMonth.with(Month.JULY);
YearMonth aug = currentYearMonth.with(Month.AUGUST);
YearMonth sep = currentYearMonth.with(Month.SEPTEMBER);
YearMonth oct = currentYearMonth.with(Month.OCTOBER);
YearMonth nov = currentYearMonth.with(Month.NOVEMBER);
YearMonth dec = currentYearMonth.with(Month.DECEMBER);

代码示例来源:origin: org.sakaiproject.calendar/sakai-calendar-util

YearMonth jan = currentYearMonth.with(Month.JANUARY);
YearMonth feb = currentYearMonth.with(Month.FEBRUARY);
YearMonth mar = currentYearMonth.with(Month.MARCH);
YearMonth apr = currentYearMonth.with(Month.APRIL);
YearMonth may = currentYearMonth.with(Month.MAY);
YearMonth jun = currentYearMonth.with(Month.JUNE);
YearMonth jul = currentYearMonth.with(Month.JULY);
YearMonth aug = currentYearMonth.with(Month.AUGUST);
YearMonth sep = currentYearMonth.with(Month.SEPTEMBER);
YearMonth oct = currentYearMonth.with(Month.OCTOBER);
YearMonth nov = currentYearMonth.with(Month.NOVEMBER);
YearMonth dec = currentYearMonth.with(Month.DECEMBER);

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Returns a copy of this year-month with the specified period in months added.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param monthsToAdd  the months to add, may be negative
 * @return a {@code YearMonth} based on this year-month with the months added, not null
 * @throws DateTimeException if the result exceeds the supported range
 */
public YearMonth plusMonths(long monthsToAdd) {
  if (monthsToAdd == 0) {
    return this;
  }
  long monthCount = year * 12L + (month - 1);
  long calcMonths = monthCount + monthsToAdd;  // safe overflow
  int newYear = YEAR.checkValidIntValue(Jdk8Methods.floorDiv(calcMonths, 12));
  int newMonth = Jdk8Methods.floorMod(calcMonths, 12) + 1;
  return with(newYear, newMonth);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public YearMonth plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    switch ((ChronoUnit) unit) {
      case MONTHS: return plusMonths(amountToAdd);
      case YEARS: return plusYears(amountToAdd);
      case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
      case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
      case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
      case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
    }
    throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
  }
  return unit.addTo(this, amountToAdd);
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com