Instant:时间线上的某个时刻(不可变信息)
---作用:可以用来记录代码的执行时间,或用于记录用户某个事件的时间点
---传统的Date类,只能精确到毫秒,并且是可变对象
---新增的Instant类,可以精确到纳秒,并且是不可变对象,推荐用Instant代替Date
package code;
import java.time.Instant;
public class Text {
public static void main(String[] args) {
//1.创建Instant的对象,获取此刻时间信息
Instant now = Instant.now();
//2.获取总秒数
long second = now.getEpochSecond();
System.out.println(second);
//3.不够1秒的纳米数
int nano = now.getNano();
System.out.println(nano);
System.out.println(now);
Instant instant = now.plusNanos(111);//加多少纳秒
//Instant对象的作用 做代码的性能分析,或记录用户的操作时间点
Instant now1 = Instant.now();
//代码执行。。。
Instant now2 = Instant.now();
}
}