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
  • 相关阅读:
    好用的绘图工具推荐-processon
    前台获取到的后台json对象取值时undefined的解决方法
    axios怎么引用?
    postman发送post请求,后端无法接收到参数
    bcrypt加密算法
    mongoose创建model名字时,为什么集合名会自动加s?
    《遇见未知的自己》 张德芬
    《把时间当做朋友》笔记摘要
    精英与普通人的区别
    金刚经全文
  • 原文地址:https://www.cnblogs.com/windy13/p/11349279.html
Copyright © 2011-2022 走看看