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