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

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

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

LocalDateTime.plus介绍

[英]Returns a copy of this date-time with the specified period added.

This method returns a new date-time based on this date-time with the specified period added. This can be used to add any period that is defined by a unit, for example to add years, months or days. The unit is responsible for the details of the calculation, including the resolution of any edge cases in the calculation.

This instance is immutable and unaffected by this method call.
[中]返回添加了指定期间的此日期时间的副本。
此方法基于此日期时间返回新的日期时间,并添加指定的期间。这可用于添加由单位定义的任何期间,例如添加年、月或日。该单位负责计算的细节,包括计算中任何边缘情况的解决方案。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

/**
 * Returns a copy of this date-time with the specified period subtracted.
 * <p>
 * This method returns a new date-time based on this date-time with the specified period subtracted.
 * This can be used to subtract any period that is defined by a unit, for example to subtract years, months or days.
 * The unit is responsible for the details of the calculation, including the resolution
 * of any edge cases in the calculation.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToSubtract  the amount of the unit to subtract from the result, may be negative
 * @param unit  the unit of the period to subtract, not null
 * @return a {@code LocalDateTime} based on this date-time with the specified period subtracted, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalDateTime minus(long amountToSubtract, TemporalUnit unit) {
  return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
}

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

/**
 * Returns a copy of this date-time with the specified period subtracted.
 * <p>
 * This method returns a new date-time based on this date-time with the specified period subtracted.
 * This can be used to subtract any period that is defined by a unit, for example to subtract years, months or days.
 * The unit is responsible for the details of the calculation, including the resolution
 * of any edge cases in the calculation.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToSubtract  the amount of the unit to subtract from the result, may be negative
 * @param unit  the unit of the period to subtract, not null
 * @return a {@code LocalDateTime} based on this date-time with the specified period subtracted, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalDateTime minus(long amountToSubtract, TemporalUnit unit) {
  return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
}

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

/**
 * Returns a copy of this date-time with the specified period added.
 * <p>
 * This method returns a new date-time based on this date-time with the specified period added.
 * This can be used to add any period that is defined by a unit, for example to add years, months or days.
 * The unit is responsible for the details of the calculation, including the resolution
 * of any edge cases in the calculation.
 * The offset is not part of the calculation and will be unchanged in the result.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the period to add, not null
 * @return an {@code OffsetDateTime} based on this date-time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public OffsetDateTime plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    return with(dateTime.plus(amountToAdd, unit), offset);
  }
  return unit.addTo(this, amountToAdd);
}

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

/**
 * Returns a copy of this date-time with the specified period added.
 * <p>
 * This method returns a new date-time based on this date-time with the specified period added.
 * This can be used to add any period that is defined by a unit, for example to add years, months or days.
 * The unit is responsible for the details of the calculation, including the resolution
 * of any edge cases in the calculation.
 * The offset is not part of the calculation and will be unchanged in the result.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param amountToAdd  the amount of the unit to add to the result, may be negative
 * @param unit  the unit of the period to add, not null
 * @return an {@code OffsetDateTime} based on this date-time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public OffsetDateTime plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    return with(dateTime.plus(amountToAdd, unit), offset);
  }
  return unit.addTo(this, amountToAdd);
}

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

if (unit instanceof ChronoUnit) {
  if (unit.isDateBased()) {
    return resolveLocal(dateTime.plus(amountToAdd, unit));
  } else {
    return resolveInstant(dateTime.plus(amountToAdd, unit));

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

if (unit instanceof ChronoUnit) {
  if (unit.isDateBased()) {
    return resolveLocal(dateTime.plus(amountToAdd, unit));
  } else {
    return resolveInstant(dateTime.plus(amountToAdd, unit));

代码示例来源:origin: net.oneandone.ical4j/ical4j

}while((ldt = ldt.plus(org.threeten.bp.Period.ofWeeks(1))).getMonth() == month);

相关文章