• JAVA 8 主要新特性 ----------------(七)新时间日期 API ----- Duration “时间”间隔


    Duration:用于计算两个“时间”间隔

    简介:

       

    用法:

    1、Zero常量

    实例:

    1 Duration duration = Duration.ZERO;
    2         System.out.println("持续时间常量值:"+duration.toNanos());
    3         System.out.println("持续时间常量值是否为零:"+duration.isZero());
    4         System.out.println("持续时间常量值是正数:"+duration.abs().toNanos());
    View Code

    2、ofDays

     实例:

    1 Duration durationOfDays =  Duration.ofDays(1);
    2         System.out.println("一天有多少小时:"+durationOfDays.toHours()+"H");
    View Code

    3、ofHours

     实例:

    1 Duration durationOfHours =  Duration.ofHours(2);
    2         System.out.println("一小时有多少分:"+durationOfHours.toMinutes()+"m");
    View Code

    4、ofMinutes

    实例:

    1 Duration durationOfMinutes =  Duration.ofMinutes(1);
    2         System.out.println("一分钟有多少秒:"+durationOfMinutes.getSeconds()+"s");
    View Code

    5、ofSeconds

    实例:

    1 Duration durationOfSeconds =  Duration.ofSeconds(1);
    2         System.out.println("一秒有多少秒:"+durationOfSeconds.getSeconds()+"s");
    View Code

    实例:

    1 Duration durationOfSecondsNano =  Duration.ofSeconds(2,2000);
    2         System.out.println("2000纳秒有多少秒:"+durationOfSecondsNano.getSeconds()+"s");
    View Code

    6、ofMillis

     实例:

    1 Duration durationOfMillis =  Duration.ofMillis(5000);
    2         System.out.println("5000纳秒有多少秒:"+durationOfMillis.getSeconds()+"s");
    View Code

    7、ofNanos

     实例:

    1 Duration durationOfNanos =  Duration.ofNanos(10000);
    2         System.out.println("10000纳秒有多少纳秒:"+durationOfNanos.toNanos()+"s");
    View Code

    8、of

    实例:

    1  Duration durationOf =  Duration.of(10,SECONDS);
    2         System.out.println("10秒有多少秒:"+durationOf.getSeconds()+"s");
    View Code

    9、from

    实例:

    1 Duration durationFrom =  Duration.from(Duration.ofDays(10));
    2         System.out.println("10天有多少小时:"+durationFrom.toHours()+"H");
    View Code

    10、parse

    实例:

    1 Duration durationParse =  Duration.parse("PT15M");
    2         System.out.println("格式转化15分钟:"+durationParse.toMinutes()+"M");
    View Code

    11、between

    实例:

    1 Duration durationBetween =  Duration.between(LocalTime.NOON,LocalTime.MAX);
    2         System.out.println("距离今天结束还有多少时间:"+durationBetween.toHours()+"时"+durationBetween.toMinutes()+"分"+durationBetween.getSeconds()+"秒");
    View Code
  • 相关阅读:
    wcf中的Message类
    wcf消息契约
    iis部署wcf服务
    WCF数据契约
    wcf配置
    wcf中的使用全双工通信
    A股主要指数的市盈率(PE)估值高度
    股票的历史市盈率查询PE
    错误 Unable to find vcvarsall.bat 的终极无敌最完美的解决办法
    A股最新的自由现金流和折现估值查询
  • 原文地址:https://www.cnblogs.com/liuyangfirst/p/10184920.html
Copyright © 2020-2023  润新知