现在方法()Java 中的实例
可以使用 Java 中 Instant 类中的 now() 方法来获得系统 UTC 时钟中的当前时间点。此方法不需要参数,它会从系统 UTC 时钟中返回当前时间点。
演示此方法的程序如下 −
示例
import java.time.*;
public class Demo {
public static void main(String[] args) {
Instant i = Instant.now();
System.out.println("The current Instant is: " + i);
}
}输出
The current Instant is: 2019-02-12T11:49:22.455Z
现在让我们理解上述程序。
我们使用 now() 方法从系统 UTC 时钟中获取当前时间点并打印出来。演示此方法的代码片段如下 −
Instant i = Instant.now();
System.out.println("The current Instant is: " + i);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP