本文整理汇总了Java中org.threeten.bp.Duration.between方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.between方法的具体用法?Java Duration.between怎么用?Java Duration.between使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.threeten.bp.Duration
的用法示例。
在下文中一共展示了Duration.between方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resetAfterRestart
import org.threeten.bp.Duration; //导入方法依赖的package包/类
@Test @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts")
public void resetAfterRestart() {
LocalDateTime firstMockStart = LocalDateTime.of(2016, 1, 1, 0, 0, 0);
LocalDateTime firstMockEnd = LocalDateTime.of(2016, 1, 1, 0, 1, 0);
when(clock.now()).thenReturn(firstMockStart);
stopwatch.start();
when(clock.now()).thenReturn(firstMockEnd);
stopwatch.stop();
Duration firstActualDuration = Duration.between(firstMockStart, firstMockEnd);
Duration firstMeasuredDuration = stopwatch.getDuration();
assertThat(firstMeasuredDuration).isEqualTo(firstActualDuration);
LocalDateTime secondMockStart = LocalDateTime.of(2016, 1, 1, 0, 5, 0);
LocalDateTime secondMockEnd = LocalDateTime.of(2016, 1, 1, 0, 10, 0);
when(clock.now()).thenReturn(secondMockStart);
stopwatch.start();
when(clock.now()).thenReturn(secondMockEnd);
stopwatch.stop();
Duration secondActualDuration = Duration.between(secondMockStart, secondMockEnd);
Duration secondMeasuredDuration = stopwatch.getDuration();
assertThat(secondMeasuredDuration).isEqualTo(secondActualDuration);
}
示例2: init
import org.threeten.bp.Duration; //导入方法依赖的package包/类
@Override
public void init(Set<ValueSpecification> values, long timeout, TimeUnit ucUnit) {
Instant start = OpenGammaClock.getInstance().instant();
TemporalUnit unit = convertUnit(ucUnit);
Duration remaining = Duration.of(timeout, unit);
_historicalSnapshot1.init(values, timeout, ucUnit);
Instant after1 = OpenGammaClock.getInstance().instant();
Duration duration1 = Duration.between(start, after1);
remaining = remaining.minus(duration1);
if (remaining.isNegative()) {
return;
}
_historicalSnapshot2.init(values, remaining.get(unit), ucUnit);
Instant after2 = OpenGammaClock.getInstance().instant();
Duration duration2 = Duration.between(after1, after2);
remaining = remaining.minus(duration2);
if (remaining.isNegative()) {
return;
}
_baseSnapshot.init(values, remaining.get(unit), ucUnit);
}
示例3: start
import org.threeten.bp.Duration; //导入方法依赖的package包/类
@Override
public void start() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime nextHour = now.truncatedTo(HOURS).plusHours(1);
Duration delay = Duration.between(now.atOffset(ZoneOffset.UTC), nextHour.atOffset(ZoneOffset.UTC));
Duration oneHour = Duration.ofHours(1);
s_logger.warn("Now {} Next {} Delay {} {}", new Object[] {now, nextHour, delay, delay.toMillis() });
_timerExecutor.scheduleAtFixedRate(new SnapshotTask(), delay.toMillis(), oneHour.toMillis(), TimeUnit.MILLISECONDS);
if (getInitializationFileName() != null) {
initializeFromFile(getInitializationFileName());
}
}
示例4: getDuration
import org.threeten.bp.Duration; //导入方法依赖的package包/类
@Override
public Duration getDuration() {
final ViewCycleState state = getState();
if (state == ViewCycleState.AWAITING_EXECUTION || state == ViewCycleState.EXECUTION_INTERRUPTED) {
return null;
}
return Duration.between(getStartTime(), getEndTime() == null ? Instant.now() : getEndTime());
}
示例5: newDuration
import org.threeten.bp.Duration; //导入方法依赖的package包/类
@Override
public Duration newDuration(final long startMicros, final long endMicros) {
if (startMicros == Long.MIN_VALUE) {
throw new IllegalArgumentException(
"startMicros cannot be Long.MIN_VALUE");
}
if (endMicros == Long.MAX_VALUE) {
throw new IllegalArgumentException(
"endMicros cannot be Long.MAX_VALUE");
}
final Instant start = Time.toInstant(startMicros);
final Instant end = Time.toInstant(endMicros);
return Duration.between(start, end);
}
示例6: stop
import org.threeten.bp.Duration; //导入方法依赖的package包/类
public void stop() {
ensureNotNull(startedAt, "called stop() before start()");
LocalDateTime endedAt = clock.now();
duration = Duration.between(startedAt, endedAt);
startedAt = null;
}
示例7: getDifferenceBetweenTimeAndNow
import org.threeten.bp.Duration; //导入方法依赖的package包/类
private Duration getDifferenceBetweenTimeAndNow(long timeStart) {
LocalDateTime today = LocalDateTime.now();
LocalDateTime otherTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeStart), ZoneId.systemDefault());
return Duration.between(otherTime, today);
}
示例8: getTimeLabel
import org.threeten.bp.Duration; //导入方法依赖的package包/类
public static String getTimeLabel(Context context, ZonedDateTime dateTime) {
String label;
ZonedDateTime now = ZonedDateTime.now();
Duration duration = Duration.between(dateTime, now);
if (duration.getSeconds() <= DateTimeFormatUtil.SEC) {
label = context.getString(R.string.about_sec_ago);
} else if (duration.getSeconds() >= SEC
&& duration.getSeconds() < HALF_OF_MIN) {
label = context.getString(R.string.few_sec_ago);
} else if (duration.getSeconds() > HALF_OF_MIN &&
duration.getSeconds() <= MINUTE_IN_SEC + HALF_MINUTE_IN_SEC) {
label = context.getString(R.string.about_minute_ago);
} else if (duration.getSeconds() > MINUTE_IN_SEC + HALF_MINUTE_IN_SEC
&& duration.getSeconds() <= HALF_HOUR_IN_SEC) {
label = context.getString(R.string.few_minutes_ago);
} else if (duration.getSeconds() > HALF_HOUR_IN_SEC
&& duration.getSeconds() <= HOUR_IN_SEC + HALF_HOUR_IN_SEC) {
label = context.getString(R.string.about_hour_ago);
} else if (duration.getSeconds() > HOUR_IN_SEC + HALF_HOUR_IN_SEC
&& duration.getSeconds() <= DAY_IN_SEC) {
label = context.getString(R.string.few_hours_ago);
} else if (duration.getSeconds() >= DAY_IN_SEC &&
duration.getSeconds() < DAY_IN_SEC + HALF_DAY_IN_SEC) {
label = context.getString(R.string.yesterday);
} else {
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern(DATE_PATTERN + " " + TWELVE_HOUR_CLOCK_PATTERN)
.withZone(ZoneId.systemDefault());
label = dateTime.format(formatter);
}
return label;
}
示例9: toDurationFriendly
import org.threeten.bp.Duration; //导入方法依赖的package包/类
public static String toDurationFriendly(Context context, Date date) {
final Instant instant = DateTimeUtils.toInstant(date);
LocalDateTime target = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
LocalDateTime now = LocalDateTime.now();
Duration duration;
if (target.isAfter(now.minusMinutes(1))) {
return context.getResources().getString(R.string.just_now);
}
if (target.isAfter(now.minusHours(1))) {
duration = Duration.between(now, target);
return context.getResources().getString(R.string.minutes_ago, Math.abs(duration.toMinutes()));
}
if (target.isAfter(now.minusDays(1))) {
duration = Duration.between(now, target);
return context.getResources().getString(R.string.hours_ago, Math.abs(duration.toHours()));
}
if (target.isAfter(now.minusWeeks(1))) {
duration = Duration.between(target, now);
return context.getResources().getString(R.string.days_ago, Math.abs(duration.toDays()));
}
// http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
return target.format(DateTimeFormatter.ISO_LOCAL_DATE);
//if (now.isEqual(target)) {
// duration = Duration.between(now, target);
// return target.format(DateTimeFormatter.ISO_TIME);
//}
// 本周
//TemporalField chinaField = WeekFields.of(Locale.CHINA).dayOfWeek();
//LocalDate start = now.with(chinaField, 1);
//LocalDate end = now.with(chinaField, 7);
//if (target.isAfter(start) && target.isBefore(end)) {
// return target.format()
//}
// 一周内
//LocalDate from = now.minusDays(7);
//if (target.isAfter(from)) {
//
// return duration.toDays() + " 天前";
//}
}
示例10: getRealTimeDuration
import org.threeten.bp.Duration; //导入方法依赖的package包/类
public Duration getRealTimeDuration(final Instant fromInstant, final Instant toInstant) {
return Duration.between(fromInstant, toInstant);
}
示例11: getRealTimeDuration
import org.threeten.bp.Duration; //导入方法依赖的package包/类
@Override
public Duration getRealTimeDuration(final Instant fromInstant, final Instant toInstant) {
return Duration.between(fromInstant, toInstant);
}
示例12: createTimeSeriesUniqueId
import org.threeten.bp.Duration; //导入方法依赖的package包/类
/**
* Creates a unique identifier.
*
* @param oid the object identifier
* @param verInstant the version instant, not null
* @param corrInstant the correction instant, not null
* @return the unique identifier
*/
protected UniqueId createTimeSeriesUniqueId(long oid, Instant verInstant, Instant corrInstant) {
String oidStr = DATA_POINT_PREFIX + oid;
Duration dur = Duration.between(verInstant, corrInstant);
String verStr = verInstant.toString() + dur.toString();
return UniqueId.of(getUniqueIdScheme(), oidStr, verStr);
}