java.time.temporal.ChronoUnit.between()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(398)

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

ChronoUnit.between介绍

暂无

代码示例

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

/**
 * Convenience method to measure elapsed time between start of query execution and completion or exception as appropriate. Do not call with a null argument or before a query has executed/exploded.
 * @param unit the time unit to convert to
 * @return the elapsed time in the given unit
 */
public long getElapsedTime(ChronoUnit unit) {
  return unit.between(executionMoment, completionMoment == null ? exceptionMoment : completionMoment);
}

代码示例来源:origin: kiegroup/optaplanner

public long getDurationInMinutes() {
  return ChronoUnit.MINUTES.between(departureUTCDateTime, arrivalUTCDateTime);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Compute the number of calendar days elapsed since the given date.
 * As it's only the calendar days difference that matter, "11.00pm" to "2.00am the day after" returns 1,
 * even if there are only 3 hours between. As well as "10am" to "2pm" both on the same day, returns 0.
 */
@Restricted(NoExternalUse.class)
public static long daysBetween(@Nonnull Date a, @Nonnull Date b){
  LocalDate aLocal = a.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
  LocalDate bLocal = b.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
  return ChronoUnit.DAYS.between(aLocal, bLocal);
}

代码示例来源:origin: floragunncom/search-guard

private static long diffDays(LocalDate to) {  
  return ChronoUnit.DAYS.between(LocalDate.now(), to);
}

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

private boolean validateIfModifiedSince(Instant lastModified) {
  if (lastModified.isBefore(Instant.EPOCH)) {
    return false;
  }
  long ifModifiedSince = getRequestHeaders().getIfModifiedSince();
  if (ifModifiedSince == -1) {
    return false;
  }
  // We will perform this validation...
  this.notModified = ChronoUnit.SECONDS.between(lastModified, Instant.ofEpochMilli(ifModifiedSince)) >= 0;
  return true;
}

代码示例来源:origin: org.springframework/spring-web

private boolean validateIfModifiedSince(Instant lastModified) {
  if (lastModified.isBefore(Instant.EPOCH)) {
    return false;
  }
  long ifModifiedSince = getRequestHeaders().getIfModifiedSince();
  if (ifModifiedSince == -1) {
    return false;
  }
  // We will perform this validation...
  this.notModified = ChronoUnit.SECONDS.between(lastModified, Instant.ofEpochMilli(ifModifiedSince)) >= 0;
  return true;
}

代码示例来源:origin: kiegroup/optaplanner

public long getDaysAfterBusDeparture() {
  return DAYS.between(bus.getDepartureDate(), date);
}

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

private static long toDays(int year, int month, int day)
{
  return DAYS.between(LocalDate.of(1970, 1, 1), LocalDate.of(year, month, day));
}

代码示例来源:origin: jtablesaw/tablesaw

public static long minutesUntil(long packedDateTimeEnd, long packedDateTimeStart) {
  return ChronoUnit.MINUTES.between(asLocalDateTime(packedDateTimeStart),
          asLocalDateTime(packedDateTimeEnd));
}

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

private boolean isValidOn(EdgeIteratorState edge, long instant) {
  GtfsStorage.EdgeType edgeType = flagEncoder.getEdgeType(edge.getFlags());
  if (edgeType == GtfsStorage.EdgeType.BOARD || edgeType == GtfsStorage.EdgeType.ALIGHT) {
    final int validityId = flagEncoder.getValidityId(edge.getFlags());
    final GtfsStorage.Validity validity = realtimeFeed.getValidity(validityId);
    final int trafficDay = (int) ChronoUnit.DAYS.between(validity.start, Instant.ofEpochMilli(instant).atZone(validity.zoneId).toLocalDate());
    return trafficDay >= 0 && validity.validity.get(trafficDay);
  } else {
    return true;
  }
}

代码示例来源:origin: jtablesaw/tablesaw

public static long hoursUntil(long packedDateTimeEnd, long packedDateTimeStart) {
  return ChronoUnit.HOURS.between(asLocalDateTime(packedDateTimeStart), asLocalDateTime(packedDateTimeEnd));
}

代码示例来源:origin: hibernate/hibernate-orm

/**
   * Set the transient property at load time based on a calculation.
   * Note that a native Hibernate formula mapping is better for this purpose.
   */
  @PostLoad
  public void calculateAge() {
    age = ChronoUnit.YEARS.between( LocalDateTime.ofInstant(
        Instant.ofEpochMilli( dateOfBirth.getTime()), ZoneOffset.UTC),
      LocalDateTime.now()
    );
  }
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Gets the time gap between now and next backup time.
 *
 * @return the time gap to next backup
 */
private long getTimeToNextBackup() {
 LocalDateTime now = LocalDateTime.now(Clock.systemUTC());
 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H:mm");
 LocalTime backupTime = LocalTime.parse(ServerConfiguration
   .get(PropertyKey.MASTER_DAILY_BACKUP_TIME), formatter);
 LocalDateTime nextBackupTime = now.withHour(backupTime.getHour())
   .withMinute(backupTime.getMinute());
 if (nextBackupTime.isBefore(now)) {
  nextBackupTime = nextBackupTime.plusDays(1);
 }
 return ChronoUnit.MILLIS.between(now, nextBackupTime);
}

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

private void makeSureHasTimeStamp(AbstractGCEvent<?> abstractEvent) {
  if (size() >= 1 && abstractEvent.getTimestamp() < 0.000001 && abstractEvent.getDatestamp() != null) {
    // looks like there is no timestamp set -> set one, because a lot depends on the timestamps
    abstractEvent.setTimestamp(ChronoUnit.MILLIS.between(getFirstDateStamp(), abstractEvent.getDatestamp()) / 1000.0);
  }
}

代码示例来源:origin: confluentinc/ksql

@Test
public void shouldDeserializeTimeMicrosToBigint() {
 shouldDeserializeTypeCorrectly(
   LogicalTypes.timeMicros().addToSchema(
     org.apache.avro.SchemaBuilder.builder().longType()),
   ChronoUnit.MICROS.between(
     LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT),
     LocalDateTime.now()),
   Schema.OPTIONAL_INT64_SCHEMA
 );
}

代码示例来源:origin: confluentinc/ksql

@Test
public void shouldDeserializeTimeMillisToBigint() {
 shouldDeserializeTypeCorrectly(
   LogicalTypes.timeMillis().addToSchema(
     org.apache.avro.SchemaBuilder.builder().intType()),
   ChronoUnit.MILLIS.between(
     LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT),
     LocalDateTime.now()),
   Schema.OPTIONAL_INT64_SCHEMA
 );
}

代码示例来源:origin: confluentinc/ksql

@Test
public void shouldDeserializeTimestampToBigint() {
 shouldDeserializeTypeCorrectly(
   LogicalTypes.timestampMillis().addToSchema(
     org.apache.avro.SchemaBuilder.builder().longType()),
   ChronoUnit.MILLIS.between(
     LocalDateTime.of(LocalDate.ofEpochDay(0), LocalTime.MIDNIGHT),
     LocalDateTime.now()),
   Schema.OPTIONAL_INT64_SCHEMA
 );
}

代码示例来源:origin: confluentinc/ksql

@Test
public void shouldDeserializeTimestampToInteger() {
 shouldDeserializeTypeCorrectly(
   LogicalTypes.timestampMicros().addToSchema(
     org.apache.avro.SchemaBuilder.builder().longType()),
   ChronoUnit.MICROS.between(
     LocalDateTime.of(LocalDate.ofEpochDay(0), LocalTime.MIDNIGHT),
     LocalDateTime.now()),
   Schema.OPTIONAL_INT64_SCHEMA
 );
}

代码示例来源:origin: confluentinc/ksql

@Test
public void shouldDeserializeDateToInteger() {
 shouldDeserializeTypeCorrectly(
   LogicalTypes.date().addToSchema(
     org.apache.avro.SchemaBuilder.builder().intType()),
   (int) ChronoUnit.DAYS.between(LocalDate.ofEpochDay(0), LocalDate.now()),
   Schema.OPTIONAL_INT32_SCHEMA
 );
}

代码示例来源:origin: confluentinc/ksql

@Test
public void shouldDeserializeDateToBigint() {
 shouldDeserializeTypeCorrectly(
   LogicalTypes.date().addToSchema(
     org.apache.avro.SchemaBuilder.builder().intType()),
   ChronoUnit.DAYS.between(LocalDate.ofEpochDay(0), LocalDate.now()),
   Schema.OPTIONAL_INT64_SCHEMA
 );
}

相关文章