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

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

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

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

The calculation for date and time units differ.

Date units operate on the local time-line. The period is first subtracted from 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 subtraction.

Time units operate on the instant time-line. The period is first subtracted from 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 subtraction.

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

代码示例

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

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

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

/**
 * Best effort calculation of this {@link GCModel}s start date based on the available information
 *
 * @return the most probable start date of this {@link GCModel}
 */
public ZonedDateTime getStartDate() {
  ZonedDateTime suggestedStartDate = ZonedDateTime.ofInstant(Instant.ofEpochMilli(getLastModified()), ZoneId.systemDefault());
  if (hasDateStamp()) {
    suggestedStartDate = getFirstDateStamp();
  } else if (hasCorrectTimestamp()) {
    double runningTimeInSeconds = getRunningTime();
    long runningTimeInMillis = (long) (runningTimeInSeconds * 1000d);
    suggestedStartDate = suggestedStartDate.minus(runningTimeInMillis, ChronoUnit.MILLIS);
  }
  return suggestedStartDate;
}

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

@Test
public void notModifiedLastModified() {
  ZonedDateTime now = ZonedDateTime.now();
  ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
  RenderingResponse responseMono = RenderingResponse.create("bar")
      .header(HttpHeaders.LAST_MODIFIED, DateTimeFormatter.RFC_1123_DATE_TIME.format(oneMinuteBeforeNow))
      .build()
      .block();
  MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com")
      .header(HttpHeaders.IF_MODIFIED_SINCE,
          DateTimeFormatter.RFC_1123_DATE_TIME.format(now))
      .build();
  MockServerWebExchange exchange = MockServerWebExchange.from(request);
  responseMono.writeTo(exchange, DefaultServerResponseBuilderTests.EMPTY_CONTEXT);
  MockServerHttpResponse response = exchange.getResponse();
  assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
  StepVerifier.create(response.getBody())
      .expectError(IllegalStateException.class)
      .verify();
}

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

public ZonedDateTime minus(TemporalAmount delta) {
  return dt.minus(delta);
}

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

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

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

@Test
public void notModifiedLastModified() {
  ZonedDateTime now = ZonedDateTime.now();
  ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
  EntityResponse<String> responseMono = EntityResponse.fromObject("bar")
      .lastModified(oneMinuteBeforeNow)
      .build()
      .block();
  MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com")
      .header(HttpHeaders.IF_MODIFIED_SINCE,
          DateTimeFormatter.RFC_1123_DATE_TIME.format(now))
      .build();
  MockServerWebExchange exchange = MockServerWebExchange.from(request);
  responseMono.writeTo(exchange, DefaultServerResponseBuilderTests.EMPTY_CONTEXT);
  MockServerHttpResponse response = exchange.getResponse();
  assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
  StepVerifier.create(response.getBody())
      .expectError(IllegalStateException.class)
      .verify();
}

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

@Test
public void notModifiedLastModified() {
  ZonedDateTime now = ZonedDateTime.now();
  ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
  ServerResponse responseMono = ServerResponse.ok()
      .lastModified(oneMinuteBeforeNow)
      .syncBody("bar")
      .block();
  MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com")
      .header(HttpHeaders.IF_MODIFIED_SINCE,
          DateTimeFormatter.RFC_1123_DATE_TIME.format(now))
      .build();
  MockServerWebExchange exchange = MockServerWebExchange.from(request);
  responseMono.writeTo(exchange, EMPTY_CONTEXT);
  MockServerHttpResponse response = exchange.getResponse();
  assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
  StepVerifier.create(response.getBody())
      .expectError(IllegalStateException.class)
      .verify();
}

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

void removeOldFiles(ZonedDateTime now)
{
  if (_retainDays>0)
  {
    // Establish expiration time, based on configured TimeZone
    long expired = now.minus(_retainDays, ChronoUnit.DAYS).toInstant().toEpochMilli();
    
    File file= new File(_filename);
    File dir = new File(file.getParent());
    String fn=file.getName();
    int s=fn.toLowerCase(Locale.ENGLISH).indexOf(YYYY_MM_DD);
    if (s<0)
      return;
    String prefix=fn.substring(0,s);
    String suffix=fn.substring(s+YYYY_MM_DD.length());
    String[] logList=dir.list();
    for (int i=0;i<logList.length;i++)
    {
      fn = logList[i];
      if(fn.startsWith(prefix)&&fn.indexOf(suffix,prefix.length())>=0)
      {        
        File f = new File(dir,fn);
        if(f.lastModified() < expired)
        {
          f.delete();
        }
      }
    }
  }
}

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

final ZonedDateTime seek = base.minus(
    (windowDistanceInterval * (pastWindows - i)),
    windowDistanceIntervalUnits);

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

dateTime = dateTime.minus(1, ChronoField.MILLI_OF_SECOND.getBaseUnit());

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

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

代码示例来源:origin: mdeverdelhan/ta4j-origins

/**
 * Constructor.
 * @param timePeriod the time period
 * @param endTime the end time of the tick period
 */
public BaseTick(Duration timePeriod, ZonedDateTime endTime) {
  checkTimeArguments(timePeriod, endTime);
  this.timePeriod = timePeriod;
  this.endTime = endTime;
  this.beginTime = endTime.minus(timePeriod);
}

代码示例来源:origin: com.sap.cloud.s4hana.cloudplatform/core

public long getTotalNumberOfExceptionsForLast( final Duration duration )
  {
    return getEntriesAfter(ZonedDateTime.now().minus(duration)).size();
  }
}

代码示例来源: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: com.linecorp.centraldogma/centraldogma-server-shaded

@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.smartrplace.logging/fendodb-core

@Override
public boolean deleteDataOlderThan(final TemporalAmount amount) throws IOException {
  Objects.requireNonNull(amount);
  final long now = proxy.getTime();
  final long limit = TimeUtils.getCurrentStart(ZonedDateTime.ofInstant(Instant.ofEpochMilli(now), TimeUtils.zone)
      .minus(amount).toInstant(), proxy.unit).toEpochMilli();
  return deleteDataFrom(limit, true);
}

代码示例来源:origin: org.fcrepo/modeshape-jcr

@Override
public DateTime minus( Duration duration ) {
  CheckArg.isNotNull(duration, "unit");
  return new ModeShapeDateTime(this.instance.minus(duration));
}

代码示例来源:origin: ModeShape/modeshape

@Override
public DateTime minus( Duration duration ) {
  CheckArg.isNotNull(duration, "unit");
  return new ModeShapeDateTime(this.instance.minus(duration));
}

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

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

代码示例来源:origin: com.teradata.benchto/benchto-driver

@Override
  public QueryExecutionResult execute(QueryExecution queryExecution, Connection connection)
      throws SQLException
  {
    QueryExecutionResult executionResult = super.execute(queryExecution, connection);
    // Queries in tests need to seemingly take non-zero duration (measured with seconds precision), even if Graphite precision is subtracted.
    ZonedDateTime newStart = ((ZonedDateTime) ReflectionTestUtils.getField(executionResult, "utcStart"))
        .minus(2, ChronoUnit.SECONDS);
    ReflectionTestUtils.setField(executionResult, "utcStart", newStart);
    return executionResult;
  }
};

相关文章

ZonedDateTime类方法