Java 中的 toMillis() 方法的持续时间
可以使用toMillis()Java中的Duration类中的方法获取以毫秒为单位的特定持续时间的值。此方法不需要参数,它返回以毫秒为单位的持续时间。
演示这一点的程序如下-
示例
import java.time.Duration;
public class Demo {
public static void main(String[] args) {
Duration d = Duration.ofSeconds(1);
System.out.println("持续时间是: " + d);
System.out.println("The number of milliseconds in 持续时间是: " + d.toMillis());
}
}输出结果持续时间是: PT1S The number of milliseconds in 持续时间是: 1000
现在让我们了解上面的程序。
首先显示持续时间。然后使用该toMillis()方法获得以毫秒为单位的持续时间值并显示。演示这一点的代码片段如下-
Duration d = Duration.ofSeconds(1);
System.out.println("持续时间是: " + d);
System.out.println("The number of milliseconds in 持续时间是: " + d.toMillis());热门推荐
10 春天变冷祝福语简短
11 学生宴祝福语简短的
12 春节后的祝福语简短
13 节日祝福语幽默简短的
14 祝寿时祝福语简短精辟
15 诗词文案祝福语简短精辟
16 朋友家住豪宅祝福语简短
17 潮汕生日谚语祝福语简短
18 天气转凉祝福语简短