日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

duration java_Java Duration类| 带示例的get()方法

發(fā)布時(shí)間:2023/12/1 java 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 duration java_Java Duration类| 带示例的get()方法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

duration java

持續(xù)時(shí)間類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()方法是一個(gè)非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會(huì)收到錯(cuò)誤消息。

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

    get()方法在返回給定單元的值時(shí)可能會(huì)引發(fā)異常。

    • DateTimeException: This exception may throw when the given amt couldn’t convert into a Duration.DateTimeException :當(dāng)給定的amt無法轉(zhuǎn)換為Duration時(shí),可能引發(fā)此異常。
    • UnsupportedTemporalTypeException: This exception may throw when the given unit is unsupported.UnsupportedTemporalTypeException :當(dāng)不支持給定單元時(shí),可能引發(fā)此異常。

Syntax:

句法:

public long get(TemporalUnit t_unit);

Parameter(s):

參數(shù):

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

    TemporalUnit t_unit –表示返回值的時(shí)間單位。

Return value:

返回值:

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

此方法的返回類型為long ,它返回給定時(shí)間單位的值。

Example:

例:

// Java program to demonstrate the example // of long get(TemporalUnit t_unit) method of Durationimport java.time.*; import java.time.temporal.*;public class GetOfDuration {public static void main(String args[]) {// Instantiates two Duration objectsDuration du1 = Duration.ofHours(1);Duration du2 = Duration.ofMinutes(5);// Display du1 and du2System.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 unitlong get_val = du1.get(ChronoUnit.SECONDS);// Display get_valSystem.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 unitget_val = du2.get(ChronoUnit.SECONDS);// Display get_valSystem.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

總結(jié)

以上是生活随笔為你收集整理的duration java_Java Duration类| 带示例的get()方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。