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

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

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

LocalTime.plus介绍

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

This method returns a new time based on this time with the specified period added. This can be used to add any period that is defined by a unit, for example to add hours, minutes or seconds. 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: stackoverflow.com

LocalTime now = LocalTime.now();
LocalTime later = now.plus(2, HOURS);

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

class Flight {
  LocalTime departure;
  Duration duration;

  LocalTime getArrival() {
    LocalTime arrival = departure.plus( duration );
    // If called *many* times, and you account for changing-data and thread-safety, you could cache this result for performance. 
    return arrival;
  }

  Flight( LocalTime departureArg , Duration durationArg ) {
    this.departure = departureArg;
    this.duration = durationArg;
  }
}

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

/**
 * Returns a copy of this time with the specified period subtracted.
 * <p>
 * This method returns a new time based on this time with the specified period subtracted.
 * This can be used to subtract any period that is defined by a unit, for example to subtract hours, minutes or seconds.
 * 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 LocalTime} based on this time with the specified period subtracted, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalTime 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 time with the specified period subtracted.
 * <p>
 * This method returns a new time based on this time with the specified period subtracted.
 * This can be used to subtract any period that is defined by a unit, for example to subtract hours, minutes or seconds.
 * 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 LocalTime} based on this time with the specified period subtracted, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public LocalTime minus(long amountToSubtract, TemporalUnit unit) {
  return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
}

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

LocalTime lt = LocalTime.parse("10:00:00", DateTimeFormat.forPattern("HH:mm:ss"));
lt = lt.plus(p);
System.out.println(lt);

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

DateMidnight midnight = new DateTime("2012-12-13T21:39:45.618").toDateMidnight();
 LocalTime localTime = new LocalTime(midnight);
 localTime.plus(period);
 formatter.print(localTime);

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

/**
 * Returns a copy of this time with the specified period added.
 * <p>
 * This method returns a new time based on this time with the specified period added.
 * This can be used to add any period that is defined by a unit, for example to add hours, minutes or seconds.
 * 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 OffsetTime} based on this time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public OffsetTime plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    return with(time.plus(amountToAdd, unit), offset);
  }
  return unit.addTo(this, amountToAdd);
}

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

/**
 * Returns a copy of this time with the specified period added.
 * <p>
 * This method returns a new time based on this time with the specified period added.
 * This can be used to add any period that is defined by a unit, for example to add hours, minutes or seconds.
 * 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 OffsetTime} based on this time with the specified period added, not null
 * @throws DateTimeException if the unit cannot be added to this type
 */
@Override
public OffsetTime plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    return with(time.plus(amountToAdd, unit), offset);
  }
  return unit.addTo(this, amountToAdd);
}

相关文章