當前位置: 首頁>>代碼示例>>Java>>正文


Java ChronoUnit.NANOS屬性代碼示例

本文整理匯總了Java中java.time.temporal.ChronoUnit.NANOS屬性的典型用法代碼示例。如果您正苦於以下問題:Java ChronoUnit.NANOS屬性的具體用法?Java ChronoUnit.NANOS怎麽用?Java ChronoUnit.NANOS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在java.time.temporal.ChronoUnit的用法示例。


在下文中一共展示了ChronoUnit.NANOS屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toChronoUnit

/**
 * To chrono unit.
 *
 * @param tu the tu
 * @return the chrono unit
 */
public static ChronoUnit toChronoUnit(final TimeUnit tu) {
    if (tu == null) {
        return null;
    }
    switch (tu) {
        case DAYS:
            return ChronoUnit.DAYS;
        case HOURS:
            return ChronoUnit.HOURS;
        case MINUTES:
            return ChronoUnit.MINUTES;
        case SECONDS:
            return ChronoUnit.SECONDS;
        case MICROSECONDS:
            return ChronoUnit.MICROS;
        case MILLISECONDS:
            return ChronoUnit.MILLIS;
        case NANOSECONDS:
            return ChronoUnit.NANOS;
        default:
            return null;
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:29,代碼來源:DateTimeUtils.java

示例2: chronoUnit

/**
 * Converts a {@code TimeUnit} to a {@code ChronoUnit}.
 * <p>
 * This handles the seven units declared in {@code TimeUnit}.
 *
 * @param unit  the unit to convert, not null
 * @return the converted unit, not null
 */
private static ChronoUnit chronoUnit(final TimeUnit unit) {
    Objects.requireNonNull(unit, "unit");
    switch (unit) {
        case NANOSECONDS:
            return ChronoUnit.NANOS;
        case MICROSECONDS:
            return ChronoUnit.MICROS;
        case MILLISECONDS:
            return ChronoUnit.MILLIS;
        case SECONDS:
            return ChronoUnit.SECONDS;
        case MINUTES:
            return ChronoUnit.MINUTES;
        case HOURS:
            return ChronoUnit.HOURS;
        case DAYS:
            return ChronoUnit.DAYS;
        default:
            throw new IllegalArgumentException("Unknown TimeUnit constant");
    }
}
 
開發者ID:groupon,項目名稱:jtier-ctx,代碼行數:29,代碼來源:Life.java

示例3: toChronoUnit

private static ChronoUnit toChronoUnit(TimeUnit unit) { 
    Objects.requireNonNull(unit, "unit"); 
    switch (unit) { 
        case NANOSECONDS: 
            return ChronoUnit.NANOS; 
        case MICROSECONDS: 
            return ChronoUnit.MICROS; 
        case MILLISECONDS: 
            return ChronoUnit.MILLIS; 
        case SECONDS: 
            return ChronoUnit.SECONDS; 
        case MINUTES: 
            return ChronoUnit.MINUTES; 
        case HOURS: 
            return ChronoUnit.HOURS; 
        case DAYS: 
            return ChronoUnit.DAYS; 
        default: 
            throw new IllegalArgumentException("Unknown TimeUnit constant"); 
    } 
}
 
開發者ID:vsilaev,項目名稱:tascalate-concurrent,代碼行數:21,代碼來源:Timeouts.java

示例4: getChildChronoUnit

/**
 * Returns the child ChronoUnit for the given ChronoUnit.
 *
 * @param chronoUnit desired ChronoUnit
 * @return child ChronoUnit of the given ChronoUnit
 */
@NotNull
public static ChronoUnit getChildChronoUnit(@NotNull ChronoUnit chronoUnit) {
    switch (requireNonNull(chronoUnit)) {
        case MICROS:
            return ChronoUnit.NANOS;
        case MILLIS:
            return ChronoUnit.MICROS;
        case SECONDS:
            return ChronoUnit.MILLIS;
        case MINUTES:
            return ChronoUnit.SECONDS;
        case HOURS:
            return ChronoUnit.MINUTES;
        case DAYS:
            return ChronoUnit.HOURS;
        case WEEKS:
            return ChronoUnit.DAYS;
        case MONTHS:
            return ChronoUnit.WEEKS;
        case YEARS:
            return ChronoUnit.MONTHS;
        case DECADES:
            return ChronoUnit.YEARS;
        case MILLENNIA:
            return ChronoUnit.DECADES;
        case ERAS:
            return ChronoUnit.MILLENNIA;
        default:
            throw new UnsupportedOperationException("Unsupported chrono unit: " + chronoUnit);
    }
}
 
開發者ID:BFergerson,項目名稱:Chronetic,代碼行數:37,代碼來源:ChronoScale.java

示例5: data_query

@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.chronology(), IsoChronology.INSTANCE},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.zoneId(), null},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.precision(), ChronoUnit.NANOS},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.zone(), OFFSET_PONE},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.offset(), OFFSET_PONE},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.localDate(), LocalDate.of(2008, 6, 30)},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.localTime(), LocalTime.of(11, 30, 59, 500)},
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKOffsetDateTime.java

示例6: data_query

@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.chronology(), IsoChronology.INSTANCE},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.zoneId(), null},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.zone(), null},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.offset(), null},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.localDate(), LocalDate.of(2007, 7, 15)},
            {TEST_2007_07_15_12_30_40_987654321, TemporalQueries.localTime(), LocalTime.of(12, 30, 40, 987654321)},
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKLocalDateTime.java

示例7: data_query

@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_12_30_40_987654321, TemporalQueries.chronology(), null},
            {TEST_12_30_40_987654321, TemporalQueries.zoneId(), null},
            {TEST_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS},
            {TEST_12_30_40_987654321, TemporalQueries.zone(), null},
            {TEST_12_30_40_987654321, TemporalQueries.offset(), null},
            {TEST_12_30_40_987654321, TemporalQueries.localDate(), null},
            {TEST_12_30_40_987654321, TemporalQueries.localTime(), TEST_12_30_40_987654321},
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKLocalTime.java

示例8: data_query

@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_11_30_59_500_PONE, TemporalQueries.chronology(), null},
            {TEST_11_30_59_500_PONE, TemporalQueries.zoneId(), null},
            {TEST_11_30_59_500_PONE, TemporalQueries.precision(), ChronoUnit.NANOS},
            {TEST_11_30_59_500_PONE, TemporalQueries.zone(), OFFSET_PONE},
            {TEST_11_30_59_500_PONE, TemporalQueries.offset(), OFFSET_PONE},
            {TEST_11_30_59_500_PONE, TemporalQueries.localDate(), null},
            {TEST_11_30_59_500_PONE, TemporalQueries.localTime(), LocalTime.of(11, 30, 59, 500)},
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKOffsetTime.java

示例9: parseDuration

static Duration parseDuration(String input) {
  if (input.startsWith("P") || input.startsWith("-P") || input.startsWith("+P")) {
    return Duration.parse(input);
  }

  String[] parts = splitNumericAndChar(input);
  String numberString = parts[0];
  String originalUnitString = parts[1];
  String unitString = originalUnitString;

  if (numberString.length() == 0) {
    throw new IllegalArgumentException(String.format("No number in duration value '%s'", input));
  }

  if (unitString.length() > 2 && !unitString.endsWith("s")) {
    unitString = unitString + "s";
  }

  ChronoUnit units;
  switch (unitString) {
    case "ns":
      units = ChronoUnit.NANOS;
      break;
    case "us":
      units = ChronoUnit.MICROS;
      break;
    case "":
    case "ms":
      units = ChronoUnit.MILLIS;
      break;
    case "s":
      units = ChronoUnit.SECONDS;
      break;
    case "m":
      units = ChronoUnit.MINUTES;
      break;
    case "h":
      units = ChronoUnit.HOURS;
      break;
    case "d":
      units = ChronoUnit.DAYS;
      break;
    default:
      throw new IllegalArgumentException(
          String.format("Could not parse time unit '%s' (try ns, us, ms, s, m, h, d)", originalUnitString));
  }

  return Duration.of(Long.parseLong(numberString), units);
}
 
開發者ID:scalecube,項目名稱:config,代碼行數:49,代碼來源:DurationParser.java

示例10: truncatedTo

/**
 * Returns a copy of this {@code Instant} truncated to the specified unit.
 * <p>
 * Truncating the instant returns a copy of the original with fields
 * smaller than the specified unit set to zero.
 * The fields are calculated on the basis of using a UTC offset as seen
 * in {@code toString}.
 * For example, truncating with the {@link ChronoUnit#MINUTES MINUTES} unit will
 * round down to the nearest minute, setting the seconds and nanoseconds to zero.
 * <p>
 * The unit must have a {@linkplain TemporalUnit#getDuration() duration}
 * that divides into the length of a standard day without remainder.
 * This includes all supplied time units on {@link ChronoUnit} and
 * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param unit  the unit to truncate to, not null
 * @return an {@code Instant} based on this instant with the time truncated, not null
 * @throws DateTimeException if the unit is invalid for truncation
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 */
public Instant truncatedTo(TemporalUnit unit) {
    if (unit == ChronoUnit.NANOS) {
        return this;
    }
    Duration unitDur = unit.getDuration();
    if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) {
        throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
    }
    long dur = unitDur.toNanos();
    if ((LocalTime.NANOS_PER_DAY % dur) != 0) {
        throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
    }
    long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos;
    long result = (nod / dur) * dur;
    return plusNanos(result - nod);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:38,代碼來源:Instant.java

示例11: truncatedTo

/**
 * Returns a copy of this {@code LocalTime} with the time truncated.
 * <p>
 * Truncating the time returns a copy of the original time with fields
 * smaller than the specified unit set to zero.
 * For example, truncating with the {@link ChronoUnit#MINUTES minutes} unit
 * will set the second-of-minute and nano-of-second field to zero.
 * <p>
 * The unit must have a {@linkplain TemporalUnit#getDuration() duration}
 * that divides into the length of a standard day without remainder.
 * This includes all supplied time units on {@link ChronoUnit} and
 * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param unit  the unit to truncate to, not null
 * @return a {@code LocalTime} based on this time with the time truncated, not null
 * @throws DateTimeException if unable to truncate
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 */
public LocalTime truncatedTo(TemporalUnit unit) {
    if (unit == ChronoUnit.NANOS) {
        return this;
    }
    Duration unitDur = unit.getDuration();
    if (unitDur.getSeconds() > SECONDS_PER_DAY) {
        throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
    }
    long dur = unitDur.toNanos();
    if ((NANOS_PER_DAY % dur) != 0) {
        throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
    }
    long nod = toNanoOfDay();
    return ofNanoOfDay((nod / dur) * dur);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:35,代碼來源:LocalTime.java

示例12: truncatedTo

/**
 * Returns a copy of this {@code LocalTime} with the time truncated.
 * <p>
 * Truncation returns a copy of the original time with fields
 * smaller than the specified unit set to zero.
 * For example, truncating with the {@link ChronoUnit#MINUTES minutes} unit
 * will set the second-of-minute and nano-of-second field to zero.
 * <p>
 * The unit must have a {@linkplain TemporalUnit#getDuration() duration}
 * that divides into the length of a standard day without remainder.
 * This includes all supplied time units on {@link ChronoUnit} and
 * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param unit  the unit to truncate to, not null
 * @return a {@code LocalTime} based on this time with the time truncated, not null
 * @throws DateTimeException if unable to truncate
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 */
public LocalTime truncatedTo(TemporalUnit unit) {
    if (unit == ChronoUnit.NANOS) {
        return this;
    }
    Duration unitDur = unit.getDuration();
    if (unitDur.getSeconds() > SECONDS_PER_DAY) {
        throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
    }
    long dur = unitDur.toNanos();
    if ((NANOS_PER_DAY % dur) != 0) {
        throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
    }
    long nod = toNanoOfDay();
    return ofNanoOfDay((nod / dur) * dur);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:35,代碼來源:LocalTime.java

示例13: truncatedTo

/**
 * Returns a copy of this {@code Instant} truncated to the specified unit.
 * <p>
 * Truncating the instant returns a copy of the original with fields
 * smaller than the specified unit set to zero.
 * The fields are calculated on the basis of using a UTC offset as seen
 * in {@code toString}.
 * For example, truncating with the {@link ChronoUnit#MINUTES MINUTES} unit will
 * round down to the nearest minute, setting the seconds and nanoseconds to zero.
 * <p>
 * The unit must have a {@linkplain TemporalUnit#getDuration() duration}
 * that divides into the length of a standard day without remainder.
 * This includes all supplied time units on {@link ChronoUnit} and
 * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param unit  the unit to truncate to, not null
 * @return an {@code Instant} based on this instant with the time truncated, not null
 * @throws DateTimeException if the unit is invalid for truncation
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 */
public Instant truncatedTo(TemporalUnit unit) {
    if (unit == ChronoUnit.NANOS) {
        return this;
    }
    Duration unitDur = unit.getDuration();
    if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) {
        throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
    }
    long dur = unitDur.toNanos();
    if ((LocalTime.NANOS_PER_DAY % dur) != 0) {
        throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
    }
    long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos;
    long result = Math.floorDiv(nod, dur) * dur ;
    return plusNanos(result - nod);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:38,代碼來源:Instant.java

示例14: truncatedTo

/**
 * Returns a copy of this {@code Duration} truncated to the specified unit.
 * <p>
 * Truncating the duration returns a copy of the original with conceptual fields
 * smaller than the specified unit set to zero.
 * For example, truncating with the {@link ChronoUnit#MINUTES MINUTES} unit will
 * round down to the nearest minute, setting the seconds and nanoseconds to zero.
 * <p>
 * The unit must have a {@linkplain TemporalUnit#getDuration() duration}
 * that divides into the length of a standard day without remainder.
 * This includes all supplied time units on {@link ChronoUnit} and
 * {@link ChronoUnit#DAYS DAYS}. Other ChronoUnits throw an exception.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param unit the unit to truncate to, not null
 * @return a {@code Duration} based on this duration with the time truncated, not null
 * @throws DateTimeException if the unit is invalid for truncation
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 * @since 9
 */
public Duration truncatedTo(TemporalUnit unit) {
    Objects.requireNonNull(unit, "unit");
    if (unit == ChronoUnit.SECONDS && (seconds >= 0 || nanos == 0)) {
        return new Duration(seconds, 0);
    } else if (unit == ChronoUnit.NANOS) {
        return this;
    }
    Duration unitDur = unit.getDuration();
    if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) {
        throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
    }
    long dur = unitDur.toNanos();
    if ((LocalTime.NANOS_PER_DAY % dur) != 0) {
        throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
    }
    long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos;
    long result = (nod / dur) * dur ;
    return plusNanos(result - nod);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:40,代碼來源:Duration.java


注:本文中的java.time.temporal.ChronoUnit.NANOS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。