java.time.LocalDateTime.minus()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(307)

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

LocalDateTime.minus介绍

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

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.

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

代码示例

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

@Override
public LocalDateTimeValue sub( DurationValue duration )
{
  return replacement( assertValidArithmetic( () -> value.minus( duration ) ) );
}

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

return Gen.of(median);
final LocalDateTime start = median.minus(size, unit);
final LocalDateTime end = median.plus(size, unit);
final long duration = Duration.between(start, end).toMillis();

代码示例来源:origin: zstackio/zstack

if (date.isAfter(now.plus(Duration.ofMinutes(RestConstants.REQUEST_DURATION_MINUTES))) || date.isBefore(now.minus(Duration.ofMinutes(RestConstants.REQUEST_DURATION_MINUTES)))) {
  throw new RestException(HttpStatus.FORBIDDEN.value(), String.format("requestTimeTooSkewed"));

代码示例来源:origin: dadoonet/fscrawler

/**
 * Update the job metadata
 * @param jobName job name
 * @param scanDate last date we scan the dirs
 * @throws Exception In case of error
 */
private void updateFsJob(String jobName, LocalDateTime scanDate) throws Exception {
  // We need to round that latest date to the lower second and
  // remove 2 seconds.
  // See #82: https://github.com/dadoonet/fscrawler/issues/82
  scanDate = scanDate.minus(2, ChronoUnit.SECONDS);
  FsJob fsJob = FsJob.builder()
      .setName(jobName)
      .setLastrun(scanDate)
      .setIndexed(stats.getNbDocScan())
      .setDeleted(stats.getNbDocDeleted())
      .build();
  fsJobFileHandler.write(jobName, fsJob);
}

代码示例来源:origin: Johnnei/JavaTorrent

public TorrentInfo(Torrent torrent, Clock clock) {
  this.torrent = torrent;
  this.clock = clock;
  this.event = TrackerEvent.EVENT_STARTED;
  lastAnnounceTime = LocalDateTime.now(clock).minus(Duration.ofSeconds(30));
}

代码示例来源:origin: zavtech/morpheus-core

@Override
public boolean hasNext() {
  if (excludes != null) {
    while (excludes.test(value) && inBounds(value)) {
      value = ascend ? value.plus(step) : value.minus(step);
    }
  }
  return inBounds(value);
}
@Override

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

LocalDateTime dt = LocalDateTime.now();
ZonedDateTime zdt = dt.atZone(ZoneId.systemDefault());
long numberOfMonths = 5L;
if (attr.creationTime().toInstant().isBefore(
    dt.minus(numberOfMonths, ChronoUnit.MONTHS).toInstant(zdt.getOffset())
  )
) {
  // do something
}

代码示例来源:origin: zavtech/morpheus-core

@Override
  public LocalDateTime next() {
    final LocalDateTime next = value;
    value = ascend ? value.plus(step) : value.minus(step);
    return next;
  }
};

代码示例来源:origin: drallieiv/KinanCity

public void cleanup() {
  LocalDateTime cleanDate = LocalDateTime.now().minus(periodInSeconds, ChronoUnit.SECONDS);
  calls = calls.stream().filter(date -> date.isBefore(cleanDate)).collect(Collectors.toList());
}

代码示例来源:origin: OpenNMS/opennms

private Instant minusOne(Instant date){
  LocalDateTime current = LocalDateTime.ofInstant(date, UTC)
      .minus(1L, unit).withMinute(0).withSecond(0);
  return current.atZone(UTC).toInstant();
}

代码示例来源:origin: org.opennms.features.flows/org.opennms.features.flows.elastic

private Instant minusOne(Instant date){
  LocalDateTime current = LocalDateTime.ofInstant(date, UTC)
      .minus(1L, unit).withMinute(0).withSecond(0);
  return current.atZone(UTC).toInstant();
}

代码示例来源:origin: Krillsson/sys-API

public void purge(int olderThan, ChronoUnit unit) {
    LocalDateTime maxAge = clock.now().minus(olderThan, unit);
    Set<HistoryEntry> toBeRemoved = new HashSet<>();
    for (HistoryEntry historyEntry : history) {
      if (historyEntry.date.isBefore(maxAge)) {
        toBeRemoved.add(historyEntry);
      }
    }

    LOGGER.trace("Purging {} entries older than {} {}", toBeRemoved.size(), olderThan, unit.name());
    toBeRemoved.forEach(history::remove);
  }
}

代码示例来源:origin: dhis2/dhis2-core

/**
 * Return the current date minus the duration specified by the given string.
 *
 * @param duration the duration string, see {@link DateUtils.getDuration}.
 * @return a Date.
 */
public static Date nowMinusDuration( String duration )
{
  Duration dr = DateUtils.getDuration( duration );
  LocalDateTime time = LocalDateTime.now().minus( dr );
  return DateUtils.getDate( time );
}

代码示例来源:origin: org.neo4j/neo4j-values

@Override
public LocalDateTimeValue sub( DurationValue duration )
{
  return replacement( assertValidArithmetic( () -> value.minus( duration ) ) );
}

代码示例来源:origin: io.moquette/moquette-broker

private void wipeExpiredSessions() {
    final LocalDateTime pin = LocalDateTime.now().minus(6, ChronoUnit.DAYS);
    final Set<String> expiredSessionsIds = this.sessions.sessionOlderThan(pin);
    for (String expiredSession : expiredSessionsIds) {
      this.sessions.removeDurableSession(expiredSession);
      this.subscriptionsStore.wipeSubscriptions(expiredSession);
    }
  }
}

代码示例来源:origin: synthetichealth/synthea

private void setPatientAge(int age) {
 LocalDateTime now = LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.of("UTC"));
 LocalDateTime bday = now.minus(age, ChronoUnit.YEARS);
 long birthdate = bday.toInstant(ZoneOffset.UTC).toEpochMilli();
 person.attributes.put(Person.BIRTHDATE, birthdate);
}

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

LocalDateTime currentTime = LocalDateTime.now();
LocalDateTime dateResult;
boolean shouldReturnLastMonday = (currentTime.getDayOfWeek() != DayOfWeek.MONDAY) ||
                 (currentTime.getDayOfWeek() != DayOfWeek.MONDAY && currentTime.getHour() < 2);
if(shouldReturnLastMonday) {
  dateResult = currentTime.minus(currentTime.getDayOfWeek().getValue() - DayOfWeek.MONDAY.getValue(), ChronoUnit.DAYS)
      .minus(currentTime.getLong(ChronoField.MILLI_OF_DAY), ChronoUnit.MILLIS)
      .plus(2, ChronoUnit.HOURS);
} else {
  dateResult = currentTime.minus(currentTime.getLong(ChronoField.MILLI_OF_DAY), ChronoUnit.MILLIS)
      .plus(2,ChronoUnit.HOURS);
}

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

/**
 * Devices registered and trusted.
 *
 * @return the set
 */
@ReadOperation
public Set<? extends MultifactorAuthenticationTrustRecord> devices() {
  val unit = DateTimeUtils.toChronoUnit(properties.getTimeUnit());
  val onOrAfter = LocalDateTime.now().minus(properties.getExpiration(), unit);
  this.mfaTrustEngine.expire(onOrAfter);
  return this.mfaTrustEngine.get(onOrAfter);
}

代码示例来源:origin: net.nemerosa.ontrack/ontrack-repository-impl

@Override
public void cleanup(int retentionDays) {
  LocalDateTime pivotDate = Time.now().minus(retentionDays, ChronoUnit.DAYS);
  getNamedParameterJdbcTemplate().update(
      "DELETE FROM APPLICATION_LOG_ENTRIES WHERE TIMESTAMP < :date",
      params("date", dateTimeForDB(pivotDate))
  );
}

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

/**
 * Devices for user.
 *
 * @param username the username
 * @return the set
 */
@ReadOperation
public Set<? extends MultifactorAuthenticationTrustRecord> devicesForUser(@Selector final String username) {
  val unit = DateTimeUtils.toChronoUnit(properties.getTimeUnit());
  val onOrAfter = LocalDateTime.now().minus(properties.getExpiration(), unit);
  this.mfaTrustEngine.expire(onOrAfter);
  return this.mfaTrustEngine.get(username, onOrAfter);
}

相关文章

LocalDateTime类方法