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

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

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

ZonedDateTime.plusDays介绍

[英]Returns a copy of this ZonedDateTime with the specified period in days added.

This operates on the local time-line, LocalDateTime#plusDays(long) to the local date-time. This is then converted back to a ZonedDateTime, using the zone ID to obtain the offset.

When converting back to ZonedDateTime, if the local date-time is in an overlap, then the offset will be retained if possible, otherwise the earlier offset will be used. If in a gap, the local date-time will be adjusted forward by the length of the gap.

This instance is immutable and unaffected by this method call.
[中]返回此ZoneDateTime的副本,并添加指定的时间段(以天为单位)。
它在本地时间线上运行,本地日期时间#加上本地日期时间(长)。然后将其转换回ZoneDateTime,使用分区ID获取偏移量。
当转换回ZoneDateTime时,如果本地日期时间重叠,那么如果可能,将保留偏移量,否则将使用较早的偏移量。如果存在间隙,本地日期时间将根据间隙的长度向前调整。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: blynkkk/blynk-server

@Override
  public ZonedDateTime getNextTriggerTime(ZonedDateTime zonedNow, ZoneId zoneId) {
    ZonedDateTime zonedStartAt = buildZonedStartAt(zonedNow, zoneId);
    return zonedStartAt.isAfter(zonedNow) ? zonedStartAt : zonedStartAt.plusDays(1);
  }
}

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

LocalDateTime localNow = LocalDateTime.now();
   ZoneId currentZone = ZoneId.of("America/Los_Angeles");
   ZonedDateTime zonedNow = ZonedDateTime.of(localNow, currentZone);
   ZonedDateTime zonedNext5 ;
   zonedNext5 = zonedNow.withHour(5).withMinute(0).withSecond(0);
   if(zonedNow.compareTo(zonedNext5) > 0)
     zonedNext5 = zonedNext5.plusDays(1);
   Duration duration = Duration.between(zonedNow, zonedNext5);
   long initalDelay = duration.getSeconds();
   ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);            
   scheduler.scheduleAtFixedRate(new MyRunnableTask(), initalDelay,
                  24*60*60, TimeUnit.SECONDS);

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

@Test
public void startAndEndDateCanIncludeLogs() throws Exception {
 ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault());
 ZonedDateTime yesterday = now.minusDays(1);
 ZonedDateTime tomorrow = now.plusDays(1);
 DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(ONLY_DATE_FORMAT);
 CommandStringBuilder commandStringBuilder = new CommandStringBuilder("export logs");
 commandStringBuilder.addOption("start-time", dateTimeFormatter.format(yesterday));
 commandStringBuilder.addOption("end-time", dateTimeFormatter.format(tomorrow));
 commandStringBuilder.addOption("log-level", "debug");
 gfshConnector.executeAndAssertThat(commandStringBuilder.toString()).statusIsSuccess();
 Set<String> acceptedLogLevels = Stream.of("info", "error", "debug").collect(toSet());
 verifyZipFileContents(acceptedLogLevels);
}

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

@Test
public void startAndEndDateCanExcludeLogs() throws Exception {
 connectIfNeeded();
 ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault());
 ZonedDateTime tomorrow = now.plusDays(1);
 DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(ONLY_DATE_FORMAT);
 CommandStringBuilder commandStringBuilder = new CommandStringBuilder("export logs");
 commandStringBuilder.addOption("start-time", dateTimeFormatter.format(tomorrow));
 commandStringBuilder.addOption("log-level", "debug");
 connector.executeAndAssertThat(commandStringBuilder.toString()).statusIsError()
   .containsOutput("No files to be exported");
}

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

ZonedDateTime zonedNextTarget = zonedNow.withHour(targetHour).withMinute(targetMin).withSecond(targetSec);
if(zonedNow.compareTo(zonedNextTarget) > 0)
  zonedNextTarget = zonedNextTarget.plusDays(1);

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

thisSecondOfMinute,
      (this.nanoOfSecond == Integer.MIN_VALUE ? 0 : this.nanoOfSecond),
      zoneId).withDayOfYear(this.dayOfYear).plusDays(daysRollover);
} else {
      thisSecondOfMinute,
      (this.nanoOfSecond == Integer.MIN_VALUE ? 0 : this.nanoOfSecond),
      zoneId).plusDays(daysRollover);

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

public ZonedDateTime plusDays(long amount) {
  return dt.plusDays(amount);
}

代码示例来源:origin: spring-cloud/spring-cloud-gateway

@Bean
  public RouteLocator testRouteLocator(RouteLocatorBuilder builder) {
    return builder.routes()
        .route("test_between_valid", r -> r.host("**.betweenvalid.org")
            .and().between(ZonedDateTime.now().minusDays(1), ZonedDateTime.now().plusDays(1))
            .filters(f -> f.prefixPath("/httpbin"))
            .uri(uri))
        .build();
  }
}

代码示例来源:origin: prestodb/presto

@Override
  public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layoutHandle, SplitSchedulingStrategy splitSchedulingStrategy)
  {
    AtopTableLayoutHandle handle = (AtopTableLayoutHandle) layoutHandle;

    AtopTableHandle table = handle.getTableHandle();

    List<ConnectorSplit> splits = new ArrayList<>();
    ZonedDateTime end = ZonedDateTime.now(timeZone);
    for (Node node : nodeManager.getWorkerNodes()) {
      ZonedDateTime start = end.minusDays(maxHistoryDays - 1).withHour(0).withMinute(0).withSecond(0).withNano(0);
      while (start.isBefore(end)) {
        ZonedDateTime splitEnd = start.withHour(23).withMinute(59).withSecond(59).withNano(0);
        Domain splitDomain = Domain.create(ValueSet.ofRanges(Range.range(TIMESTAMP_WITH_TIME_ZONE, 1000 * start.toEpochSecond(), true, 1000 * splitEnd.toEpochSecond(), true)), false);
        if (handle.getStartTimeConstraint().overlaps(splitDomain) && handle.getEndTimeConstraint().overlaps(splitDomain)) {
          splits.add(new AtopSplit(table.getTable(), node.getHostAndPort(), start.toEpochSecond(), start.getZone()));
        }
        start = start.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
      }
    }

    return new FixedSplitSource(splits);
  }
}

代码示例来源:origin: blynkkk/blynk-server

@Override
  public ZonedDateTime getNextTriggerTime(ZonedDateTime zonedNow, ZoneId zoneId) {
    ZonedDateTime zonedStartAt = buildZonedStartAt(zonedNow, zoneId);

    switch (dayOfMonth) {
      case LAST:
        zonedStartAt = zonedStartAt.with(TemporalAdjusters.lastDayOfMonth());
        return zonedStartAt.isAfter(zonedNow)
            ? zonedStartAt
            : zonedStartAt.plusDays(1).with(TemporalAdjusters.lastDayOfMonth());
      case FIRST:
      default:
        zonedStartAt = zonedStartAt.with(TemporalAdjusters.firstDayOfMonth());
        return zonedStartAt.isAfter(zonedNow)
            ? zonedStartAt
            : zonedStartAt.with(TemporalAdjusters.firstDayOfNextMonth());

    }
  }
}

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

if(inputDateWithCurrentYear.isAfter(currentDate.plusDays(4L))) {
  ZonedDateTime inputDateWithPreviousYear =
      ZonedDateTime.of(currentYear-1, inputMonth, inputDay, inputHour, inputMinute, inputSecond, 0, deviceTimeZone);

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

dateTime = dateTime.with(LocalTime.MIN);
} else {
  dateTime = dateTime.plusDays(sign * num);
  dateTime = dateTime.plusDays(1);

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

final ZonedDateTime input = ZonedDateTime.now();
System.out.println(input);
final ZonedDateTime startOfLastWeek = input.minusWeeks(1).with(DayOfWeek.MONDAY);
System.out.println(startOfLastWeek);
final ZonedDateTime endOfLastWeek = startOfLastWeek.plusDays(6);
System.out.println(endOfLastWeek);

代码示例来源:origin: jzyong/game-server

public static long offsetCurrentTimeMillis(int offsetDays, int hour, int minute, int secord) {
  ZonedDateTime ldt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault());
  if (offsetDays > 0) {
    ldt = ldt.plusDays(offsetDays);
  } else if (offsetDays < 0) {
    ldt = ldt.minusDays(offsetDays);
  }
  ldt = ldt.withHour(hour);
  ldt = ldt.withMinute(minute);
  ldt = ldt.withSecond(secord);
  return ldt.toEpochSecond() * 1000;
}

代码示例来源:origin: UniversaBlockchain/universa

static Contract createSimpleContract(PrivateKey key) {
  Contract result = new Contract();
  // default expiration date
  result.setExpiresAt(ZonedDateTime.now().plusDays(90));
  // issuer role is a key for a new contract
  result.setIssuerKeys(key.getPublicKey().getShortAddress());
  // issuer is owner, link roles
  result.registerRole(new RoleLink("owner", "issuer"));
  result.registerRole(new RoleLink("creator", "issuer"));
  return result;
}

代码示例来源:origin: OpenGamma/Strata

public void coverage() {
 SabrParametersIborCapletFloorletVolatilities test1 =
   SabrParametersIborCapletFloorletVolatilities.of(NAME, EUR_EURIBOR_3M, DATE_TIME, PARAM);
 coverImmutableBean(test1);
 SabrParametersIborCapletFloorletVolatilities test2 = SabrParametersIborCapletFloorletVolatilities.of(
   NAME2, IborIndices.EUR_LIBOR_3M, DATE_TIME.plusDays(1), IborCapletFloorletSabrRateVolatilityDataSet.SABR_PARAM_FLAT);
 coverBeanEquals(test1, test2);
}

代码示例来源:origin: OpenGamma/Strata

public void coverage() {
 NormalIborFutureOptionExpirySimpleMoneynessVolatilities test =
   NormalIborFutureOptionExpirySimpleMoneynessVolatilities.of(EUR_EURIBOR_3M, VAL_DATE_TIME, PARAMETERS_RATE);
 coverImmutableBean(test);
 NormalIborFutureOptionExpirySimpleMoneynessVolatilities test2 =
   NormalIborFutureOptionExpirySimpleMoneynessVolatilities.of(
     EUR_EURIBOR_6M, VAL_DATE_TIME.plusDays(1), PARAMETERS_PRICE);
 coverBeanEquals(test, test2);
}

代码示例来源:origin: OpenGamma/Strata

public void coverage() {
  SabrParametersSwaptionVolatilities test1 = SabrParametersSwaptionVolatilities.of(NAME, CONV, DATE_TIME, PARAM);
  coverImmutableBean(test1);
  SabrParametersSwaptionVolatilities test2 = SabrParametersSwaptionVolatilities.of(
    NAME2,
    SwaptionSabrRateVolatilityDataSet.SWAP_CONVENTION_EUR,
    DATE_TIME.plusDays(1),
    SwaptionSabrRateVolatilityDataSet.SABR_PARAM_USD);
  coverBeanEquals(test1, test2);
 }
}

代码示例来源:origin: OpenGamma/Strata

public void coverage() {
 BlackBondFutureExpiryLogMoneynessVolatilities test1 = BlackBondFutureExpiryLogMoneynessVolatilities.of(
   VAL_DATE_TIME, SURFACE);
 coverImmutableBean(test1);
 BlackBondFutureExpiryLogMoneynessVolatilities test2 = BlackBondFutureExpiryLogMoneynessVolatilities.of(
   VAL_DATE_TIME.plusDays(1), SURFACE.withParameter(0, 1d));
 coverBeanEquals(test1, test2);
}

代码示例来源:origin: OpenGamma/Strata

public void coverage() {
 HullWhiteOneFactorPiecewiseConstantParametersProvider test1 =
   HullWhiteOneFactorPiecewiseConstantParametersProvider.of(PARAMETERS, ACT_360, DATE_TIME);
 coverImmutableBean(test1);
 HullWhiteOneFactorPiecewiseConstantParameters params = HullWhiteOneFactorPiecewiseConstantParameters.of(
   0.02, DoubleArray.of(0.01, 0.011, 0.014), DoubleArray.of(0.5, 5.0));
 HullWhiteOneFactorPiecewiseConstantParametersProvider test2 =
   HullWhiteOneFactorPiecewiseConstantParametersProvider.of(params, ACT_ACT_ISDA, DATE_TIME.plusDays(1));
 coverBeanEquals(test1, test2);
}

相关文章

ZonedDateTime类方法