org.apache.brooklyn.util.time.Time.elapsedSince()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(1.2k)|赞(0)|评价(0)|浏览(181)

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

Time.elapsedSince介绍

[英]returns the duration elapsed since the given timestamp (UTC)
[中]返回自给定时间戳(UTC)以来经过的持续时间

代码示例

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

/** true iff it has been longer than the given duration since the given timestamp */
public static boolean hasElapsedSince(long timestamp, Duration duration) {
  return elapsedSince(timestamp).compareTo(duration) > 0;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

@Test
public void testElapsedSince() {
  long aFewSecondsAgo = System.currentTimeMillis() - 7*1000;
  
  Duration aFewSeconds = Time.elapsedSince(aFewSecondsAgo);
  Assert.assertTrue(aFewSeconds.toMilliseconds() > 5*1000);
  Assert.assertTrue(10*1000 > aFewSeconds.toMilliseconds());
  
  Assert.assertTrue(Time.hasElapsedSince(aFewSecondsAgo, Duration.FIVE_SECONDS));
  Assert.assertFalse(Time.hasElapsedSince(aFewSecondsAgo, Duration.TEN_SECONDS));
  Assert.assertTrue(Time.hasElapsedSince(-1, Duration.TEN_SECONDS));
}

相关文章