获取Instant对象的方法,Instant.now(),返回的是一个Instant对象,这个Instant对象包含的是当前本初子午线的标准时间
要转换成北京时间需要添加偏移量(北京在东八区),操作如下:
import java.time.Instant;
Instant instant = Instant.now();
OffsetDateTime beijingTime = instant.atOffset(ZoneOffset.ofHours(8));
System.out.println(biejingTime);
Instant还可与Date相互转换
1.Instant---->Date
Date date = Date.from(instant);
2.Date--->Instant
Instant instant = date.toInstant();