可以使用now()Java中Instant类中的方法从系统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);