zoukankan      html  css  js  c++  java
  • java8时间有关新特性


    //
    LocalDate、LocalTime、LocalDateTime LocalDateTime ldt = LocalDateTime.now(); System.out.println(ldt); //2019-08-13T22:30:11.982 LocalDateTime ldt2 = LocalDateTime.of(2015, 10, 19, 13, 22, 22); System.out.println(ldt2); //2015-10-19T13:22:22 LocalDateTime ldt3 = ldt.plusYears(2); System.out.println(ldt3); //2021-08-13T22:30:11.982 LocalDateTime ldt4 = ldt.minusMonths(2); System.out.println(ldt4); //2019-06-13T22:30:11.982 System.out.println(ldt.getYear()); //2019 System.out.println(ldt.getMonthValue()); //8 System.out.println(ldt.getDayOfMonth()); //13 System.out.println(ldt.getHour()); //22 System.out.println(ldt.getMinute()); //30 System.out.println(ldt.getSecond()); //11
    Instant 时间戳(以unix元年:1970年1月1日00:00:00到某个时间之间的毫秒值)
    // Instant 时间戳(以unix元年:1970年1月1日00:00:00到某个时间之间的毫秒值)
    Instant instant=Instant.now();
    System.out.println(instant.toEpochMilli());

    // Duration 用来计算两个时间之间的间隔

    // Duration 用来计算两个时间之间的间隔
    Instant instant=Instant.now();
    Thread.sleep(1000);
    Instant instant1=Instant.now();
    Duration duration=Duration.between(instant,instant1);
    System.out.println(duration.toMillis());
    //1009
    LocalTime localTime=LocalTime.now();
    Thread.sleep(1000);
    LocalTime localTime1= LocalTime.now();
    Duration duration=Duration.between(localTime,localTime1);
    System.out.println(duration.toMillis());
    //1003
                    

    // Period 用来计算两个日期之间的间隔

    LocalDate localDate = LocalDate.of(2015, 1, 1);
    LocalDate localDate1 = LocalDate.now();
    Period between = Period.between(localDate, localDate1);
    System.out.println(between.getYears());
    // 4
    System.out.println(between.getMonths());
    // 7
    System.out.println(between.getDays());
    // 12
  • 相关阅读:
    客户端相关知识学习(三)之Android原生与H5交互的实现
    客户端相关知识学习(二)之h5与原生app交互的原理
    nslookup基础用法
    十大渗透测试演练系统
    最新的windows xp sp3序列号(绝对可通过正版验证)
    Metasploit基础命令
    msf回退一步
    验证SMB登入
    Nmap使用指南(1)
    postgreSql基础命令及linux下postgreSql命令
  • 原文地址:https://www.cnblogs.com/windy13/p/11349279.html
Copyright © 2011-2022 走看看