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
  • 相关阅读:
    把EXE可执行文件等作为资源包含在Delphi编译文件中
    在DBGrid增加一列CheckBox(而非DBCheckBox)
    TCanvas 类属性及方法
    Windows RPC
    Meteor入门
    IntelliJ IDEA 开发scala
    Web前端开发实用的Chrome插件
    Postman 是一个非常棒的Chrome扩展,提供功能强大的API & HTTP 请求调试
    Ruby入门--Linux/Windows下的安装、代码开发及Rails实战
    IntelliJIDEA Getting+Started+with+Spring+MVC,+Hibernate+and+JSON
  • 原文地址:https://www.cnblogs.com/windy13/p/11349279.html
Copyright © 2011-2022 走看看