java.time.ZonedDateTime.plus()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(212)

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

ZonedDateTime.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.

The calculation for date and time units differ.

Date units operate on the local time-line. The period is first added to the local date-time, then converted back to a zoned date-time using the zone ID. The conversion uses #ofLocal(LocalDateTime,ZoneId,ZoneOffset)with the offset before the addition.

Time units operate on the instant time-line. The period is first added to the local date-time, then converted back to a zoned date-time using the zone ID. The conversion uses #ofInstant(LocalDateTime,ZoneOffset,ZoneId)with the offset before the addition.

This instance is immutable and unaffected by this method call.
[中]返回添加了指定时间段的此日期时间的副本。
此方法基于此日期时间返回新的日期时间,并添加指定的期间。这可用于添加单位定义的任何期间,例如添加年、月或日。该部门负责计算的细节,包括计算中任何边缘情况的解决方案。
日期和时间单位的计算方法不同。
日期单位在当地时间线上运行。周期首先添加到本地日期时间,然后使用区域ID转换回分区日期时间。转换使用#ofLocal(LocalDateTime、ZoneId、ZoneOffset)和添加前的偏移量。
时间单位在即时时间线上运行。周期首先添加到本地日期时间,然后使用区域ID转换回分区日期时间。转换使用#of Instant(LocalDateTime、ZoneOffset、ZoneId)和添加前的偏移量。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: neo4j/neo4j

@Override
public DateTimeValue add( DurationValue duration )
{
  return replacement( assertValidArithmetic( () -> value.plus( duration ) ) );
}

代码示例来源:origin: oracle/helidon

/**
 * Get current (or as configured) time.
 *
 * @return a date time with a time-zone information as configured for this instance
 */
public ZonedDateTime get() {
  ZonedDateTime zdt = ZonedDateTime.now();
  zdt = zdt.withZoneSameInstant(timeZone);
  zdt = zdt.plus(shiftSeconds, ChronoUnit.SECONDS);
  for (ChronoValues chronoValues : this.chronoValues) {
    zdt = zdt.with(chronoValues.field, chronoValues.value);
  }
  return zdt;
}

代码示例来源:origin: jdbi/jdbi

public Instant advance(long amountToAdd, TemporalUnit unit) {
  now = now.plus(amountToAdd, unit);
  return instant();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void shouldNotFailPreconditionForPutRequests() throws Exception {
  servletRequest.setMethod("PUT");
  ZonedDateTime dateTime = ofEpochMilli(new Date().getTime()).atZone(GMT);
  servletRequest.addHeader(HttpHeaders.IF_UNMODIFIED_SINCE, RFC_1123_DATE_TIME.format(dateTime));
  long justModified = dateTime.plus(1, ChronoUnit.SECONDS).toEpochSecond() * 1000;
  ResponseEntity<String> returnValue = ResponseEntity.ok()
      .lastModified(justModified).body("body");
  initStringMessageConversion(TEXT_PLAIN);
  processor.handleReturnValue(returnValue, returnTypeResponseEntity, mavContainer, webRequest);
  assertConditionalResponse(HttpStatus.OK, null, null, justModified);
}

代码示例来源:origin: wildfly/wildfly

zonedDateTime = zonedDateTime.truncatedTo(ChronoUnit.DAYS)
      .withDayOfYear(1)
      .plus(1, ChronoUnit.YEARS);
  break;
case MONTH:
  zonedDateTime =  zonedDateTime.truncatedTo(ChronoUnit.DAYS)
      .withDayOfMonth(1)
      .plus(1,ChronoUnit.MONTHS);
  break;
case WEEK:
case DAY:
  zonedDateTime = zonedDateTime.truncatedTo(ChronoUnit.DAYS)
      .plus(1, ChronoUnit.DAYS);
  break;
case HALF_DAY:
  ZonedDateTime halfDay = ZonedDateTime.from(zonedDateTime).truncatedTo(ChronoUnit.DAYS)
      .plus(1, ChronoUnit.HALF_DAYS);
  if ( zonedDateTime.isBefore(halfDay) ) {
    zonedDateTime = halfDay;
  }else{
    zonedDateTime = halfDay.plus(1, ChronoUnit.HALF_DAYS);
      .plus(1, ChronoUnit.HOURS);
  break;
case MINUTE:
  zonedDateTime = zonedDateTime.truncatedTo(ChronoUnit.MINUTES)
      .plus(1, ChronoUnit.MINUTES);

代码示例来源:origin: chewiebug/GCViewer

/**
 * Make sure, time / datestamp of <code>vmOpEvent</code> is at least as long later as the
 * pause duration of <code>previousEvent</code>.
 *
 * @param previousEvent event just before <code>vmOpEvent</code>
 * @param vmOpEvent     event to be adjusted
 */
private void adjustTimeStamp(AbstractGCEvent<?> previousEvent, VmOperationEvent vmOpEvent) {
  if (previousEvent.getTimestamp() + previousEvent.getPause() > vmOpEvent.getTimestamp()) {
    vmOpEvent.setTimestamp(previousEvent.getTimestamp() + previousEvent.getPause());
    if (previousEvent.getDatestamp() != null) {
      Duration adjustment = Duration.ofMinutes((long) Math.rint(previousEvent.getPause() / 60))
          .plus((long) Math.rint(previousEvent.getPause()), ChronoUnit.SECONDS)
          .plus((long) Math.rint(previousEvent.getPause() * 1000), ChronoUnit.MILLIS);
      ZonedDateTime adjustedDatestamp = previousEvent.getDatestamp().plus(adjustment);
      vmOpEvent.setDateStamp(adjustedDatestamp);
    }
  }
}

代码示例来源:origin: apache/geode

long mockSystemTime = now.plus(i, ChronoUnit.SECONDS).toInstant().toEpochMilli();
when(processCpuTime.longValue()).thenReturn(mockProcessCpuTime);
when(vmStatsMonitor.currentTimeMillis()).thenReturn(mockSystemTime);

代码示例来源:origin: org.elasticsearch/elasticsearch

public ZonedDateTime plus(TemporalAmount amount) {
  return dt.plus(amount);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public ZonedDateTime plus(long amount,TemporalUnit unit) {
  return dt.plus(amount, unit);
}

代码示例来源:origin: org.eclipse.jetty/jetty-util

/**
 * Get the "start of day" for the provided DateTime at the zone specified.
 *
 * @param now the date time to calculate from
 * @return start of the day of the date provided
 */
public static ZonedDateTime toMidnight(ZonedDateTime now)
{
  return now.toLocalDate().atStartOfDay(now.getZone()).plus(1, ChronoUnit.DAYS);
}

代码示例来源:origin: facebook/jcommon

void advanceMillis(int millis) {
  now = now.plus(millis, ChronoUnit.MILLIS);
 }
}

代码示例来源:origin: biezhi/learn-java8

public static void main(String[] args) {
    // 创建一个ZonedDateTime实例
    ZonedDateTime dateTime = ZonedDateTime.now();

    // 使用指定的年月日、时分秒、纳秒以及时区ID来新建对象
    ZoneId        zoneId    = ZoneId.of("UTC+8");
    ZonedDateTime dateTime2 = ZonedDateTime.of(2018, 3, 8, 23, 45, 59, 1234, zoneId);

    // 3天后
    ZonedDateTime zoneDateTime = dateTime2.plus(Period.ofDays(3));

    ZoneId zoneId2 = ZoneId.of("Europe/Copenhagen");
    ZoneId zoneId3 = ZoneId.of("Europe/Paris");

    System.out.println("dateTime     : " + dateTime);
    System.out.println("zoneDateTime : " + zoneDateTime);
    System.out.println("zoneId2      : " + zoneId2);
    System.out.println("zoneId3      : " + zoneId3);
  }
}

代码示例来源:origin: yahoo/egads

ZonedDateTime model_ts = Instant.ofEpochSecond(modelStartEpoch)
    .atZone(zone);
ZonedDateTime end_ts = model_ts.plus(windowSize, windowUnits);
int prediction_index = 0;
final List<WeightedValue> accumulator = Lists.newArrayList();
    windowTimes[i] = windowTimes[i].plus(interval,
        intervalUnits);
    long interval_end = windowTimes[i].toEpochSecond();
      WeightedValue.aggregate(accumulator, windowAggregator)));
  model_ts = model_ts.plus(interval, intervalUnits);
  if (model_ts.toEpochSecond() > end_ts.toEpochSecond()) {
    prediction_index++;
    model_ts = model_ts.plus(
        (windowDistanceInterval * prediction_index), 
        windowDistanceIntervalUnits);
    end_ts = model_ts.plus(windowSize, windowUnits);
    for (int i = 0; i < windowTimes.length; i++) {
      windowTimes[i] = null;

代码示例来源:origin: zeebe-io/zeebe

public long toEpochMilli(long fromEpochMilli) {
 if (!isCalendarBased()) {
  return fromEpochMilli + getDuration().toMillis();
 }
 final Instant start = Instant.ofEpochMilli(fromEpochMilli);
 final ZonedDateTime zoneAwareStart = ZonedDateTime.ofInstant(start, ZoneId.systemDefault());
 return zoneAwareStart.plus(this).toInstant().toEpochMilli();
}

代码示例来源:origin: line/centraldogma

@VisibleForTesting
ZonedDateTime nextExecutionTime(ZonedDateTime lastExecutionTime, long jitterMillis) {
  requireNonNull(lastExecutionTime, "lastExecutionTime");
  final ZonedDateTime next =
      executionTime.nextExecution(lastExecutionTime.minus(jitterMillis, ChronoUnit.MILLIS));
  return next.plus(jitterMillis, ChronoUnit.MILLIS);
}

代码示例来源:origin: org.apereo.cas/cas-server-support-oauth-core

/**
 * Is refresh token expired ?
 *
 * @param ticketState the ticket state
 * @return the boolean
 */
@JsonIgnore
protected boolean isRefreshTokenExpired(final TicketState ticketState) {
  val expiringTime = ticketState.getCreationTime().plus(this.timeToKillInSeconds, ChronoUnit.SECONDS);
  return ticketState == null || expiringTime.isBefore(ZonedDateTime.now(ZoneOffset.UTC));
}

代码示例来源:origin: hawkular/hawkular-metrics

/**
 * Intended to be used at the startup of the MetricsServiceImpl to ensure we have enough tables for processing
 */
public void verifyAndCreateTempTables() {
  ZonedDateTime currentBlock = ZonedDateTime.ofInstant(Instant.ofEpochMilli(DateTimeService.now.get().getMillis()), UTC)
      .with(DateTimeService.startOfPreviousEvenHour());
  ZonedDateTime lastStartupBlock = currentBlock.plus(6, ChronoUnit.HOURS);
  verifyAndCreateTempTables(currentBlock, lastStartupBlock).await();
}

代码示例来源:origin: hawkular/hawkular-metrics

@Override
  public Completable call(JobDetails jobDetails) {

    Trigger trigger = jobDetails.getTrigger();

    ZonedDateTime currentBlock = ZonedDateTime.ofInstant(Instant.ofEpochMilli(trigger.getTriggerTime()), UTC)
        .with(DateTimeService.startOfPreviousEvenHour());

    ZonedDateTime lastMaintainedBlock = currentBlock.plus(forwardTime);

    return service.verifyAndCreateTempTables(currentBlock, lastMaintainedBlock)
        .doOnCompleted(() -> logger.debugf("Temporary tables are valid until %s",
            lastMaintainedBlock.toString()));
  }
}

代码示例来源:origin: org.hawkular.metrics/hawkular-metrics-core-service

@Override
  public Completable call(JobDetails jobDetails) {

    Trigger trigger = jobDetails.getTrigger();

    ZonedDateTime currentBlock = ZonedDateTime.ofInstant(Instant.ofEpochMilli(trigger.getTriggerTime()), UTC)
        .with(DateTimeService.startOfPreviousEvenHour());

    ZonedDateTime lastMaintainedBlock = currentBlock.plus(forwardTime);

    return service.verifyAndCreateTempTables(currentBlock, lastMaintainedBlock)
        .doOnCompleted(() -> logger.debugf("Temporary tables are valid until %s",
            lastMaintainedBlock.toString()));
  }
}

代码示例来源:origin: espertechinc/esper

public ZonedDateTime evaluate(ZonedDateTime zdt, EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext context) {
  if (code == ApacheCommonsDateUtils.MODIFY_TRUNCATE) {
    return zdt.truncatedTo(fieldName.getChronoUnit());
  } else if (code == ApacheCommonsDateUtils.MODIFY_CEILING) {
    return zdt.plus(1, fieldName.getChronoUnit()).truncatedTo(fieldName.getChronoUnit());
  } else {
    throw new EPException("Round-half operation not supported for ZonedDateTime");
  }
}

相关文章

ZonedDateTime类方法