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

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

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

ChronoUnit.isTimeBased介绍

[英]Checks if this unit is a time unit.
[中]检查此单位是否为时间单位。

代码示例

代码示例来源:origin: optimatika/ojAlgo

public boolean isTimeBased() {
  if (myChronoUnit != null) {
    return myChronoUnit.isTimeBased();
  } else { // QUARTER
    return false;
  }
}

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

public boolean isTimeBased() {
  if (myChronoUnit != null) {
    return myChronoUnit.isTimeBased();
  } else { // QUARTER
    return false;
  }
}

代码示例来源:origin: com.github.seratch/java-time-backport

@Override
public long until(Temporal endExclusive, TemporalUnit unit) {
  @SuppressWarnings("unchecked")
  ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) toLocalDate().getChronology().localDateTime(endExclusive);
  if (unit instanceof ChronoUnit) {
    ChronoUnit f = (ChronoUnit) unit;
    if (f.isTimeBased()) {
      long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY);
      switch (f) {
        case NANOS: amount = Jdk8Methods.safeMultiply(amount, NANOS_PER_DAY); break;
        case MICROS: amount = Jdk8Methods.safeMultiply(amount, MICROS_PER_DAY); break;
        case MILLIS: amount = Jdk8Methods.safeMultiply(amount, MILLIS_PER_DAY); break;
        case SECONDS: amount = Jdk8Methods.safeMultiply(amount, SECONDS_PER_DAY); break;
        case MINUTES: amount = Jdk8Methods.safeMultiply(amount, MINUTES_PER_DAY); break;
        case HOURS: amount = Jdk8Methods.safeMultiply(amount, HOURS_PER_DAY); break;
        case HALF_DAYS: amount = Jdk8Methods.safeMultiply(amount, 2); break;
      }
      return Jdk8Methods.safeAdd(amount, time.until(end.toLocalTime(), unit));
    }
    ChronoLocalDate endDate = end.toLocalDate();
    if (end.toLocalTime().isBefore(time)) {
      endDate = endDate.minus(1, ChronoUnit.DAYS);
    }
    return date.until(endDate, unit);
  }
  return unit.between(this, end);
}

代码示例来源:origin: com.github.seratch/java-time-backport

if (unit instanceof ChronoUnit) {
  ChronoUnit f = (ChronoUnit) unit;
  if (f.isTimeBased()) {
    long daysUntil = date.daysUntil(end.date);
    long timeUntil = end.time.toNanoOfDay() - time.toNanoOfDay();

相关文章