Instant的使用

2022年11月22日09:27:41
/*
    Instant的使用
    类似于Java.util.Date类
     */
    @Test

    public void test2(){
        //now():对应本初子午线对应的标准时间
        Instant instant = Instant.now();
        System.out.println(instant);
        //添加时间的偏移量
        OffsetDateTime offsetDateTime = instant.atOffset(ZoneOffset.ofHours(8));
        System.out.println(offsetDateTime);


        //toEpochMilli:获取对应的毫秒数-->Date.getTime()
        long milli = instant.toEpochMilli();
        System.out.println(milli);

        //ofEpochMilli:通过给定的毫秒数,获取Instant实例--->Date(long millis)
        Instant instant1 = Instant.ofEpochMilli(1645728380);
        System.out.println(instant1);
    }
  • 作者:爱吃早饭的小王
  • 原文链接:https://blog.csdn.net/m0_55895641/article/details/123140833
    更新时间:2022年11月22日09:27:41 ,共 481 字。