org.fujion.common.DateUtil.formatElapsed()方法的使用及代码示例

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

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

DateUtil.formatElapsed介绍

[英]Return elapsed time in ms to displayable format with units.
[中]以毫秒为单位将经过的时间返回为可显示格式,单位为。

代码示例

代码示例来源:origin: org.fujion/fujion-common

/**
 * Return elapsed time in ms to displayable format with units.
 *
 * @param elapsed Elapsed time in ms.
 * @return Elapsed time in displayable format.
 */
public static String formatElapsed(double elapsed) {
  return formatElapsed(elapsed, true, false, false);
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * Return elapsed time in ms to displayable format with units.
 *
 * @param elapsed Elapsed time in ms.
 * @param pluralize If true, pluralize units when appropriate.
 * @param abbreviated If true, use abbreviated form of units.
 * @param round If true, round result to an integer.
 * @return Elapsed time in displayable format.
 */
public static String formatElapsed(double elapsed, boolean pluralize, boolean abbreviated, boolean round) {
  return formatElapsed(elapsed, pluralize, abbreviated, round, null);
}

代码示例来源:origin: org.fujion/fujion-common

/**
 * Return elapsed time in ms to displayable format with units.
 *
 * @param elapsed Elapsed time in ms.
 * @return Elapsed time in displayable format.
 * @param minUnits Minimum units for return value (null = ms).
 */
public static String formatElapsed(double elapsed, TimeUnit minUnits) {
  return formatElapsed(elapsed, true, false, false, minUnits);
}

代码示例来源:origin: org.fujion/fujion-common

@Test
public void testElapsed() {
  assertEquals("0.1 seconds", DateUtil.formatElapsed(100.0, TimeUnit.SECONDS));
  assertEquals("1 second", DateUtil.formatElapsed(1000.0));
  assertEquals("1 minute", DateUtil.formatElapsed(60000.0));
  assertEquals("3.59 days", DateUtil.formatElapsed(309898934.0));
  assertEquals("98.2 years", DateUtil.formatElapsed(3098989343984.0));
  assertEquals("-98.2 years", DateUtil.formatElapsed(-3098989343984.0));
  
  assertEquals(100.0, DateUtil.parseElapsed("0.1 seconds"), 0.0);
  assertEquals(1000.0, DateUtil.parseElapsed("1 second"), 0.0);
  assertEquals(60000.0, DateUtil.parseElapsed("1 minute"), 0.0);
  assertEquals(310176000.0, DateUtil.parseElapsed("3.59 days"), 0.0);
  assertEquals(3098956320000.0, DateUtil.parseElapsed("98.2 years"), 0.0);
  assertEquals(-3098956320000.0, DateUtil.parseElapsed("-98.2 years"), 0.0);
  assertEquals(98.2, DateUtil.parseElapsed("98.2 years", TimeUnit.YEARS), 0.0);
}

相关文章