Java 中 Duration 的 toMillis()
可以使用 Java 中 Duration 类中的 toMillis() 方法来获得特定持续时间在毫秒数量中的值。此方法不需要参数,且返回毫秒数量中的持续时间。
以下给出了演示此功能的程序 −
示例
import java.time.Duration;
public class Demo {
public static void main(String[] args) {
Duration d = Duration.ofSeconds(1);
System.out.println("The duration is: " + d);
System.out.println("The number of milliseconds in the duration is: " + d.toMillis());
}
}输出
The duration is: PT1S The number of milliseconds in the duration is: 1000
现在让我们来理解上述程序。
首先显示持续时间。然后使用 toMillis() 方法获取持续时间在毫秒数中的值并显示。演示此功能的代码片段如下 −
Duration d = Duration.ofSeconds(1);
System.out.println("The duration is: " + d);
System.out.println("The number of milliseconds in the duration is: " + d.toMillis());
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP