• 俩个时间对比


    看了java8时间的计算时间差:

    http://www.php.cn/java-article-407521.html

    大概有三种 Period:

            LocalDate today = LocalDate.now();

            LocalDate birthDate = LocalDate.of(1993, Month.OCTOBER, 19);

            System.out.println("BirthDate : " + birthDate);

            Period p = Period.between(birthDate, today);

            System.out.printf("年龄 : %d 年 %d 月 %d 日", p.getYears(), p.getMonths(), p.getDays());

    Duration:

    Duration duration= Duration.between( date1.toInstant(),date2.toInstant());
    long t=duration.toDays();
    你也可以转换整个时间到其它单位如纳秒、分钟、小时、天:
    long seconds =  getSeconds()
    int nanos   =   getNano()
    toNanos()
    toMillis()
    toMinutes()
    toHours()
    toDays()
    一些加减的方法:https://blog.csdn.net/tjgykhulj/article/details/69053873

    ChronoUnit:

    LocalDate startDate = LocalDate.of(1993, Month.OCTOBER, 19);

            System.out.println("开始时间  : " + startDate);

            LocalDate endDate = LocalDate.of(2017, Month.JUNE, 16);

            System.out.println("结束时间 : " + endDate);

            long daysDiff = ChronoUnit.DAYS.between(startDate, endDate);

            System.out.println("两天之间的差在天数   : " + daysDiff);

     
     
  • 相关阅读:
    8.5 day8
    8.1 day6
    课后作业 day29
    博客整理day29
    博客整理day28
    博客整理day27
    博客整理day26
    课后作业 day26
    Python 学习day22
    课后作业 day21
  • 原文地址:https://www.cnblogs.com/xiaoxiaojuan/p/10186461.html
Copyright © 2020-2023  润新知