Instant:时间线上的一个瞬时点。Instant的使用类似于java.util.Date类
- now():(静态方法)获取此时本初子午线的标准时间,属于实例化
Instant i1 = Instant.now();System.out.println(i1);//2022-08-23T02:50:28.259934400Z----输出的是此时本初子午线那的时间
- ofEpochMilli(long milli):(静态方法)通过给定的毫秒数,获取Instant实例,和Data(long milli)类似;属于实例化
Instant i3 = Instant.ofEpochMilli(1661223459724L);
- atOffset(ZoneOffset offset):结合时区的偏移量来创建一个 OffsetDateTime
OffsetDateTime i2 = i1.atOffset(ZoneOffset.ofHours(8));//我们这是东八区,所以参数是ZoneOffset.ofHours(8)
System.out.println(i2);//输出2022-08-23T10:53:49.070431400+08:00`
- toEpochMilli():获取自1970-01-01 00:00:00到当前时间的毫秒数,即为时间戳,和Date.getTime()类似。
long l = i1.toEpochMilli();
由以上可知,一般实例化的方法都是静态的,其他的方法都是非静态的