本文整理汇总了Java中java.time.Duration.minusHours方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.minusHours方法的具体用法?Java Duration.minusHours怎么用?Java Duration.minusHours使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Duration
的用法示例。
在下文中一共展示了Duration.minusHours方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatAsElapsed
import java.time.Duration; //导入方法依赖的package包/类
public static String formatAsElapsed() {
Duration elapsed = Duration.ofMillis(ManagementFactory.getRuntimeMXBean().getUptime());
long days = elapsed.toDays();
elapsed = elapsed.minusDays(days);
long hours = elapsed.toHours();
elapsed = elapsed.minusHours(hours);
long minutes = elapsed.toMinutes();
elapsed = elapsed.minusMinutes(minutes);
long seconds = elapsed.getSeconds();
elapsed = elapsed.minusSeconds(seconds);
long millis = elapsed.toMillis();
return String.format(TIME_FORMAT,
days,
hours,
minutes,
seconds,
millis);
}
示例2: minusHours_long
import java.time.Duration; //导入方法依赖的package包/类
@Test(dataProvider="MinusHours")
public void minusHours_long(long hours, long amount, long expectedHours) {
Duration t = Duration.ofHours(hours);
t = t.minusHours(amount);
assertEquals(t.toHours(), expectedHours);
}
示例3: minusHours_long_overflowTooBig
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions = {ArithmeticException.class})
public void minusHours_long_overflowTooBig() {
Duration t = Duration.ofHours(Long.MAX_VALUE/3600);
t.minusHours(-1);
}
示例4: minusHours_long_overflowTooSmall
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions = {ArithmeticException.class})
public void minusHours_long_overflowTooSmall() {
Duration t = Duration.ofHours(Long.MIN_VALUE/3600);
t.minusHours(1);
}