[英]Gets the duration of this unit, which may be an estimate.
All units return a duration measured in standard nanoseconds from this method. The duration will be positive and non-zero. For example, an hour has a duration of 60 * 60 * 1,000,000,000ns.
Some units may return an accurate duration while others return an estimate. For example, days have an estimated duration due to the possibility of daylight saving time changes. To determine if the duration is an estimate, use #isDurationEstimated(). [中]获取此单位的持续时间,它可能是一个估计值。 所有单位都会返回一个持续时间,以该方法中的标准纳秒为单位。持续时间将为正且非零。例如,一小时的持续时间为60601000000000ns。 一些单位可能会返回准确的持续时间,而其他单位则会返回估计值。例如,由于夏令时可能会发生变化,因此天数具有估计的持续时间。要确定持续时间是否为估计值,请使用#isDurationEstimated()。
代码示例
代码示例来源:origin: jtablesaw/tablesaw
return packedTime; Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > SECONDS_PER_DAY) { throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
/** * The total amount of time in this time period measured in seconds, the base SI unit of time. * * @return the total amount of time in this time period measured in seconds. */ public double totalSeconds() { final double nanoSecOndsPerSecond= 1E9; Duration thisDuration = this.timeUnit.getDuration(); double secOnds= thisDuration.getSeconds() * this.periodLength; double nanos = thisDuration.getNano(); nanos = (nanos * this.periodLength); nanos = (nanos / nanoSecondsPerSecond); return seconds + nanos; }
private static long getNext(long time, TemporalUnit unit, long multiplier, ZoneId zoneId) { final long end; try { if (!unit.isDateBased()) end = time + unit.getDuration().multipliedBy(multiplier).toMillis(); else end = ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), zoneId).plus(multiplier, unit).toInstant().toEpochMilli(); } catch (ArithmeticException e) { return multiplier > 0 ? Long.MAX_VALUE : Long.MIN_VALUE; } if (multiplier > 0 && end
return this; Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) { throw new DateTimeException("Unit is too large to be used for truncation");
return this; Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > SECONDS_PER_DAY) { throw new DateTimeException("Unit is too large to be used for truncation");
代码示例来源:origin: org.threeten/threeten-extra
long fromNanos = fromUnit.getDuration().toNanos(); long tOnanos= toUnit.getDuration().toNanos(); if (fromNanos > toNanos) { long multiple = fromNanos / toNanos;
private final static long getAlignedIntervalStartTime(ReadOnlyTimeSeries timeSeries, long startTime, long samplingInterval, final ZoneId timeZone) { final Instant t0; if (timeSeries != null) { final SampledValue sv = timeSeries.getNextValue(startTime); if (sv == null) return startTime; t0 = Instant.ofEpochMilli(sv.getTimestamp()); } else { t0 = Instant.ofEpochMilli(startTime); } for (TemporalUnit unit :units) { if (samplingInterval == unit.getDuration().toMillis()) { if (!unit.isDateBased()) return t0.truncatedTo(unit).toEpochMilli(); else { final ZonedDateTime day = ZonedDateTime.ofInstant(t0, timeZone).truncatedTo(ChronoUnit.DAYS); final ZonedDateTime truncated; if (unit == ChronoUnit.WEEKS) truncated = day.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); else if (unit == ChronoUnit.MONTHS) truncated = day.with(TemporalAdjusters.firstDayOfMonth()); else truncated = day.with(TemporalAdjusters.firstDayOfYear()); return truncated.toInstant().toEpochMilli(); } } } return startTime; }
代码示例来源:origin: tech.tablesaw/tablesaw-core
return packedTime; Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > SECONDS_PER_DAY) { throw new UnsupportedTemporalTypeException("Unit is too large to be used for truncation");