java clock计时_Java Clock类| offset()方法与示例
java clock計時
Clock Class offset()方法 (Clock Class offset() method)
offset() method is available in java.time package.
offset()方法在java.time包中可用。
offset() method is used to generate a new Clock from the given base clock with added the given Duration.
offset()方法用于根據給定的基本時鐘加上給定的Duration來生成新Clock。
offset() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
offset()方法是一個靜態方法,可以使用類名進行訪問,如果嘗試使用類對象訪問該方法,則不會出錯。
offset() method does not throw an exception at the time of representing Clock.
offset()方法在表示Clock時不會引發異常。
Syntax:
句法:
public static Clock offset(Clock base_cl, Duration off);Parameter(s):
參數:
Clock base_cl – represents the base clock in which to add the given duration.
Clock base_cl –表示要添加給定持續時間的基本時鐘。
Duration off – represents the offset to add to the given base clock (base_cl).
持續時間關閉 –表示要添加到給定基本時鐘(base_cl)的偏移量。
Return value:
返回值:
The return type of this method is Clock, it returns the Clock object that is available with added the given offset.
此方法的返回類型為Clock ,它返回添加了給定偏移量后可用的Clock對象。
Example:
例:
// Java program to demonstrate the example // of offset(Clock base_cl, Duration off) method of Clockimport java.time.*;public class OffsetOfClock {public static void main(String args[]) {// Instantiates two ZoneId for Accra and AsmaraZoneId zone_1 = ZoneId.of("Africa/Accra");ZoneId zone_2 = ZoneId.of("Africa/Asmara");// Initialize two Clock objects // and one DurationClock cl1 = Clock.system(zone_1);Clock cl2 = Clock.system(zone_2);Duration offset = Duration.ofMinutes(20);// generates a new Clock from the// given clock(cl1) with the given duration addedClock cl_offset = cl1.offset(cl1, offset);// Display cl1 and cl_offset instantSystem.out.println("cl1.instant(): " + cl1.instant());System.out.println("cl_offset.instant(): " + cl_offset.instant());System.out.println();// generates a new Clock from the// given clock(cl2) with the given duration addedcl_offset = cl2.offset(cl2, offset);// Display cl2 and cl_offset instantSystem.out.println("cl2.instant(): " + cl2.instant());System.out.println("cl_offset.instant(): " + cl_offset.instant());} }Output
輸出量
cl1.instant(): 2020-05-13T19:04:36.242559Z cl_offset.instant(): 2020-05-13T19:24:36.322896Zcl2.instant(): 2020-05-13T19:04:36.324623Z cl_offset.instant(): 2020-05-13T19:24:36.327267Z翻譯自: https://www.includehelp.com/java/clock-offset-method-with-example.aspx
java clock計時
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的java clock计时_Java Clock类| offset()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: arm tbh_TBH的完整形式是什么?
- 下一篇: hashmap put方法_Java H