gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-17 20:16:40 33 4
gpt4 key购买 nike

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

ZonedDateTime.minusSeconds介绍

[英]Returns a copy of this ZonedDateTime with the specified period in seconds subtracted.

This operates on the instant time-line, such that subtracting one second will always be a duration of one second earlier. This may cause the local date-time to change by an amount other than one second. Note that this is a different approach to that used by days, months and years.

This instance is immutable and unaffected by this method call.
[中]返回此ZoneDateTime的副本,并减去指定的时间段(以秒为单位)。
这是在即时时间线上进行的,因此减去一秒的持续时间将始终提前一秒。这可能会导致本地日期时间的变化量超过1秒。请注意,这与日、月和年使用的方法不同。
此实例是不可变的,不受此方法调用的影响。

代码示例

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

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

代码示例来源:origin: org.codehaus.groovy/groovy-datetime

/**
 * Returns a {@link java.time.ZonedDateTime} that is {@code seconds} seconds before this date/time.
 *
 * @param self    a ZonedDateTime
 * @param seconds the number of seconds to subtract
 * @return a ZonedDateTime
 * @since 2.5.0
 */
public static ZonedDateTime minus(final ZonedDateTime self, long seconds) {
  return self.minusSeconds(seconds);
}

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

@Override
public void decreaseExpiresAt(int decreaseSeconds) {
  expiresAt = expiresAt.minusSeconds(decreaseSeconds);
}

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

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

代码示例来源:origin: apache/servicemix-bundles

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

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

ZonedDateTime java8DateTime = ZonedDateTime.now();  // uses ZoneId.systemDefault()
ZonedDateTime java8DateTimeInPast = java8DateTime.minusSeconds(60);
doSomething(java8DateTimeInPast.toInstant());

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

/**
 * Gets failure in range cut off date.
 *
 * @return the failure in range cut off date
 */
protected Date getFailureInRangeCutOffDate() {
  val cutoff = ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(getFailureRangeInSeconds());
  return DateTimeUtils.timestampOf(cutoff);
}

代码示例来源:origin: logzio/sawmill

private static Map<String, Object> generateApacheLog() {
  Map<String,Object> map = new HashMap<>();
  String datetime = ZonedDateTime.now().minusSeconds(random.nextInt(3000)).format(DateTimeFormatter.ofPattern("dd/MMM/yyyy:HH:mm:ss Z"));
  String ip = faker.internet().ipV4Address();
  String method = getRandomItemFromList(methods);
  String response = getRandomItemFromList(responses);
  String resource = "/" + String.join("/", resources.subList(random.nextInt(5), 4 + random.nextInt(5)));
  String ua = getRandomItemFromList(userAgents);
  String bytes = String.valueOf(random.nextInt(5000));
  String referrer = faker.internet().url();
  map.put("message",
      String.format("%s - - [%s] \"%s %s HTTP/1.1\" %s %s \"%s\" \"%s\"",ip, datetime, method, resource, response, bytes, referrer, ua));
  return map;
}

代码示例来源:origin: com.conveyal/r5

void addItinerary(Integer accessIdx, Integer egressIdx,
  List<TransitJourneyID> transitJourneyIDs, ZoneId timeZone) {
  Itinerary itinerary = new Itinerary();
  itinerary.transfers = transitJourneyIDs.size() - 1;
  itinerary.walkTime = access.get(accessIdx).duration+egress.get(egressIdx).duration;
  itinerary.distance = access.get(accessIdx).distance+egress.get(egressIdx).distance;
  ZonedDateTime transitStart = transit.get(0).segmentPatterns.get(transitJourneyIDs.get(0).pattern).fromDepartureTime.get(transitJourneyIDs.get(0).time);
  itinerary.startTime = transitStart.minusSeconds(access.get(accessIdx).duration);
  int lastTransit = transitJourneyIDs.size()-1;
  ZonedDateTime transitStop = transit.get(lastTransit).segmentPatterns.get(transitJourneyIDs.get(lastTransit).pattern).toArrivalTime.get(transitJourneyIDs.get(lastTransit).time);
  itinerary.endTime = transitStop.plusSeconds(egress.get(egressIdx).duration);
  itinerary.duration = (int) Duration.between(itinerary.startTime,itinerary.endTime).getSeconds();
  itinerary.transitTime = 0;
  int transitJourneyIDIdx=0;
  for(TransitJourneyID transitJourneyID: transitJourneyIDs) {
    itinerary.transitTime += transit.get(transitJourneyIDIdx).getTransitTime(transitJourneyID);
    transitJourneyIDIdx++;
  }
  itinerary.waitingTime=itinerary.duration-(itinerary.transitTime+itinerary.walkTime);
  PointToPointConnection pointToPointConnection = new PointToPointConnection(accessIdx, egressIdx, transitJourneyIDs);
  itinerary.addConnection(pointToPointConnection);
  this.itinerary.add(itinerary);
}

代码示例来源:origin: conveyal/r5

void addItinerary(Integer accessIdx, Integer egressIdx,
  List<TransitJourneyID> transitJourneyIDs, ZoneId timeZone) {
  Itinerary itinerary = new Itinerary();
  itinerary.transfers = transitJourneyIDs.size() - 1;
  itinerary.walkTime = access.get(accessIdx).duration+egress.get(egressIdx).duration;
  itinerary.distance = access.get(accessIdx).distance+egress.get(egressIdx).distance;
  ZonedDateTime transitStart = transit.get(0).segmentPatterns.get(transitJourneyIDs.get(0).pattern).fromDepartureTime.get(transitJourneyIDs.get(0).time);
  itinerary.startTime = transitStart.minusSeconds(access.get(accessIdx).duration);
  int lastTransit = transitJourneyIDs.size()-1;
  ZonedDateTime transitStop = transit.get(lastTransit).segmentPatterns.get(transitJourneyIDs.get(lastTransit).pattern).toArrivalTime.get(transitJourneyIDs.get(lastTransit).time);
  itinerary.endTime = transitStop.plusSeconds(egress.get(egressIdx).duration);
  itinerary.duration = (int) Duration.between(itinerary.startTime,itinerary.endTime).getSeconds();
  itinerary.transitTime = 0;
  int transitJourneyIDIdx=0;
  for(TransitJourneyID transitJourneyID: transitJourneyIDs) {
    itinerary.transitTime += transit.get(transitJourneyIDIdx).getTransitTime(transitJourneyID);
    transitJourneyIDIdx++;
  }
  itinerary.waitingTime=itinerary.duration-(itinerary.transitTime+itinerary.walkTime);
  PointToPointConnection pointToPointConnection = new PointToPointConnection(accessIdx, egressIdx, transitJourneyIDs);
  itinerary.addConnection(pointToPointConnection);
  this.itinerary.add(itinerary);
}

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

@Override
protected void renderMergedOutputModel(final Map<String, Object> model,
                    final HttpServletRequest request,
                    final HttpServletResponse response) throws Exception {
  try {
    response.setCharacterEncoding(this.encoding);
    val service = this.samlArgumentExtractor.extractService(request);
    val serviceId = getServiceIdFromRequest(service);
    LOGGER.debug("Using [{}] as the recipient of the SAML response for [{}]", serviceId, service);
    val samlResponse = this.samlObjectBuilder.newResponse(
      this.samlObjectBuilder.generateSecureRandomId(),
      ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(this.skewAllowance), serviceId, service);
    LOGGER.debug("Created SAML response for service [{}]", serviceId);
    prepareResponse(samlResponse, model);
    LOGGER.debug("Starting to encode SAML response for service [{}]", serviceId);
    this.samlObjectBuilder.encodeSamlResponse(response, request, samlResponse);
  } catch (final Exception e) {
    LOGGER.error("Error generating SAML response for service", e);
    throw e;
  }
}

代码示例来源:origin: com.cronutils/cron-utils

/**
 * Provide nearest date for last execution.
 *
 * @param date - ZonedDateTime instance. If null, a NullPointerException will be raised.
 * @return Optional ZonedDateTime instance, never null. Last execution time or empty.
 */
public Optional<ZonedDateTime> lastExecution(final ZonedDateTime date) {
  Preconditions.checkNotNull(date);
  try {
    ZonedDateTime previousMatch = previousClosestMatch(date);
    if (previousMatch.equals(date)) {
      previousMatch = previousClosestMatch(date.minusSeconds(1));
    }
    return Optional.of(previousMatch);
  } catch (final NoSuchValueException e) {
    return Optional.empty();
  }
}

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

/**
   * {@inheritDoc}
   * The CRL next update time is compared against the current time with the threshold
   * applied and rejected if and only if the next update time is in the past.
   *
   * @param crl CRL instance to evaluate.
   * @throws ExpiredCRLException On expired CRL data. Check the exception type for exact details
   */
  @Override
  public void apply(final X509CRL crl) throws ExpiredCRLException {
    val cutoff = ZonedDateTime.now(ZoneOffset.UTC);
    if (CertUtils.isExpired(crl, cutoff)) {
      if (CertUtils.isExpired(crl, cutoff.minusSeconds(this.threshold))) {
        throw new ExpiredCRLException(crl.toString(), cutoff, this.threshold);
      }
      LOGGER.info(String.format("CRL expired on %s but is within threshold period, %s seconds.",
        crl.getNextUpdate(), this.threshold));
    }
  }
}

代码示例来源:origin: SonarSource/sonarlint-intellij

@Test
public void testSet() {
 SonarLintProjectState state = new SonarLintProjectState();
 state.setLastEventPolling(ZonedDateTime.now());
 assertThat(state.getLastEventPolling()).isBeforeOrEqualTo(ZonedDateTime.now());
 assertThat(state.getLastEventPolling()).isAfter(ZonedDateTime.now().minusSeconds(3));
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void queryForCreatedAtIsGreaterThan() {
  createdAtTest((m, date) -> m.isGreaterThan(date.minusSeconds(1)));
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void queryForCreatedAtIsGreaterThanOrEqualTo() {
  createdAtTest((m, date) -> m.isGreaterThanOrEqualTo(date.minusSeconds(1)));
}

代码示例来源:origin: com.cronutils/cron-utils

private static ExecutionTimeResult getPreviousPotentialValue(
    final ZonedDateTime date,
    final TimeNode node,
    final TemporalField field) throws NoSuchValueException {
  Set<Integer> values = new HashSet<>(node.values);
  TemporalUnit unit = field.getBaseUnit();
  long maximum = field.range().getMaximum();
  long minimum = field.range().getMinimum();
  long range = maximum - minimum;
  ZonedDateTime newDate = date;
  for (long i = 0; i < 2 * range; i++) {
    newDate = newDate.minus(1, unit);
    if (values.contains(newDate.get(field))) {
      newDate = newDate
          .truncatedTo(unit)
          .plus(1, unit)
          .minusSeconds(1);
      return new ExecutionTimeResult(newDate, false);
    }
  }
  throw new NoSuchValueException();
}

代码示例来源:origin: cloudfoundry-incubator/multiapps-controller

public Health getHealth() {
  HealthCheckConfiguration healthCheckConfiguration = configuration.getHealthCheckConfiguration();
  ZonedDateTime currentTime = currentTimeSupplier.get();
  ZonedDateTime xSecondsAgo = currentTime.minusSeconds(healthCheckConfiguration.getTimeRangeInSeconds());
  OperationFilter filter = new OperationFilter.Builder().mtaId(healthCheckConfiguration.getMtaId())
    .spaceId(healthCheckConfiguration.getSpaceId())
    .user(healthCheckConfiguration.getUserName())
    .endedAfter(Date.from(xSecondsAgo.toInstant()))
    .inFinalState()
    .orderByEndTime()
    .descending()
    .build();
  List<Operation> healthCheckOperations = operationDao.find(filter);
  return Health.fromOperations(healthCheckOperations);
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void getCompletedAt() throws Exception {
  final ZonedDateTime completedAt = SphereTestUtils.now().minusSeconds(5555);
  testOrderAspect(builder -> builder.completedAt(completedAt),
      order -> assertThat(order.getCompletedAt()).isEqualTo(completedAt));
}

代码示例来源:origin: apache/incubator-rya

@Test
public void testSeconds() throws DatatypeConfigurationException, ValueExprEvaluationException {
  DatatypeFactory dtf = DatatypeFactory.newInstance();
  ZonedDateTime zTime = testThisTimeDate;
  String time = zTime.format(DateTimeFormatter.ISO_INSTANT);
  ZonedDateTime zTime1 = zTime.minusSeconds(1);
  String time1 = zTime1.format(DateTimeFormatter.ISO_INSTANT);
  Literal now = VF.createLiteral(dtf.newXMLGregorianCalendar(time));
  Literal nowMinusOne = VF.createLiteral(dtf.newXMLGregorianCalendar(time1));
  DateTimeWithinPeriod func = new DateTimeWithinPeriod();
  assertEquals(TRUE, func.evaluate(VF, now, now, VF.createLiteral(1), OWLTime.SECONDS_URI));
  assertEquals(FALSE, func.evaluate(VF, now, nowMinusOne,VF.createLiteral(1), OWLTime.SECONDS_URI));
  assertEquals(TRUE, func.evaluate(VF, now, nowMinusOne,VF.createLiteral(2), OWLTime.SECONDS_URI));
}

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