duration java

持续时间类get()方法 (Duration Class get() method)

  • get() method is available in java.time package.

    get()方法在java.time包中可用。

  • get() method is used to return the value for the given unit.

    get()方法用于返回给定单位的值。

  • get() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    get()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • get() method may throw an exception at the time of returning value for the given unit.

    get()方法在返回给定单元的值时可能会引发异常。

    • DateTimeException: This exception may throw when the given amt couldn’t convert into a Duration.DateTimeException :当给定的amt无法转换为Duration时,可能引发此异常。
    • UnsupportedTemporalTypeException: This exception may throw when the given unit is unsupported.UnsupportedTemporalTypeException :当不支持给定单元时,可能引发此异常。

Syntax:

句法:

    public long get(TemporalUnit t_unit);

Parameter(s):

参数:

  • TemporalUnit t_unit – represents the temporal unit of the returned value.

    TemporalUnit t_unit –表示返回值的时间单位。

Return value:

返回值:

The return type of this method is long, it returns the value for the given temporal unit.

此方法的返回类型为long ,它返回给定时间单位的值。

Example:

例:

// Java program to demonstrate the example
// of long get(TemporalUnit t_unit) method of Duration
import java.time.*;
import java.time.temporal.*;
public class GetOfDuration {public static void main(String args[]) {// Instantiates two Duration objects
Duration du1 = Duration.ofHours(1);
Duration du2 = Duration.ofMinutes(5);
// Display du1 and du2
System.out.println("du1: " + du1);
System.out.println("du2: " + du2);
// gets the value of the given unit i.e.
// here we are requesting the value of
// du1 in SECONDS unit
long get_val = du1.get(ChronoUnit.SECONDS);
// Display get_val
System.out.println("du1.get(ChronoUnit.SECONDS): " + get_val);
// gets the value of the given unit i.e.
// here we are requesting the value of
// du2 in SECONDS unit
get_val = du2.get(ChronoUnit.SECONDS);
// Display get_val
System.out.println("du2.get(ChronoUnit.SECONDS): " + get_val);
}
}

Output

输出量

du1: PT1H
du2: PT5M
du1.get(ChronoUnit.SECONDS): 3600
du2.get(ChronoUnit.SECONDS): 300

翻译自: https://www.includehelp.com/java/duration-get-method-with-example.aspx

duration java

duration java_Java Duration类| 带示例的get()方法相关推荐

  1. duration java_Java Duration类| 带示例的getUnits()方法

    duration java 持续时间类getUnits()方法 (Duration Class getUnits() method) getUnits() method is available in ...

  2. duration java_Java Duration类| 带示例的dividBy()方法

    duration java 持续时间类divideBy()方法 (Duration Class dividedBy() method) dividedBy() method is available ...

  3. duration java_Java Duration类| 带示例的multipliedBy()方法

    duration java 持续时间类multipliedBy()方法 (Duration Class multipliedBy() method) multipliedBy() method is ...

  4. duration java_Java Duration类| toNanos()方法与示例

    duration java Duration Class toNanos()方法 (Duration Class toNanos() method) toNanos() method is avail ...

  5. duration java_Java Duration类| ofMinutes()方法与示例

    duration java Duration Class of Minutes()方法 (Duration Class ofMinutes() method) ofMinutes() method i ...

  6. duration java_Java Duration类| withSeconds()方法与示例

    duration java 持续时间类withSeconds()方法 (Duration Class withSeconds() method) withSeconds() method is ava ...

  7. duration java_Java Duration类| minusMinutes()方法与示例

    duration java 持续时间类minusMinutes()方法 (Duration Class minusMinutes() method) minusMinutes() method is ...

  8. duration java_Java Duration类| ofHours()方法与示例

    duration java Duration Class of Hours()方法 (Duration Class ofHours() method) ofHours() method is avai ...

  9. duration java_Java Duration类| plusDays()方法与示例

    duration java 持续时间类plusDays()方法 (Duration Class plusDays() method) plusDays() method is available in ...

最新文章

  1. 面向对象设计领域的OCP原则
  2. 新书上市 | 当我们在谈论贝叶斯时我们在谈论什么:用贝叶斯的眼光看世界
  3. mysql创建新表失败_MySQL创建表失败的问题
  4. mysql 问号作用_什么是MySQL中的问号的意义“WHERE column =?”?
  5. Zabbix 2.4.5 自定义 key 监控 apache
  6. 计算机视觉之OpenCV教程 --- Mat图像类基础(二)
  7. python读数据库的通信协议是,Python操作SQLite数据库过程解析
  8. html快捷键_Mac进阶:掌握这 5 个冷门快捷键,让Mac更好用
  9. windows下安装HTK3.4
  10. Bugku 杂项刷题日常1--21:
  11. 第四季-专题2-U-Boot新手入门
  12. c语言通讯录整体设计论文,通讯录管理系统的设计与实现
  13. 运放专题:电压比较器
  14. 美国国家人工智能研发战略规划2019
  15. 利用DRONEKIT-SITL + MAVPROXY + QGroundControl模拟飞行
  16. 微信小程序客服消息配置 token 验证失败 微信无请求记录 问题现象的解决办法
  17. oracle timeatamp,oracle12c_Temporal Validity
  18. 2月综艺节目网络关注度榜出炉 《王牌对王牌》跃居榜首
  19. CSP拼图问题--矩阵快速幂
  20. 软件测试面试题:关闭浏览器中quit和close的区别

热门文章

  1. python rtf转txt_将DOC、RTF格式文件批量转为TXT格式文件
  2. 微信公众号网页开发:播放视频,在列表中滑动会脱离文档流
  3. HTTP协议/RTSP协议/RTMP协议的区别
  4. 两天学会css基础(一)
  5. mysql中ibdata1过大的问题
  6. 组合数据类型练习,英文词频统计实例上(2017.9.22)
  7. TP3.2之WHERE组合条件处理
  8. MarkDownPad2 注册码
  9. 一起动手打造个人娱乐级linux
  10. 夺命雷公狗---ECSHOP---08---商品页的拇改成星星