clock.tick
Clock Class tick()方法 (Clock Class tick() method)
tick() method is available in java.time package.
tick()方法在java.time包中可用。
tick() method is used to get a Clock that returns the current instant tick the given base clock (base_cl) discarded to the close occurrence of the given duration (time_du).
tick()方法用于获取一个Clock,该Clock返回丢弃给定持续时间(time_du)的给定基本时钟(base_cl)的当前瞬间滴答。
tick() 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.
tick()方法是静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会收到错误。
tick() method does not throw an exception at the time of representing Clock.
tick()方法在表示Clock时不会引发异常。
Syntax:
句法:
public static Clock tick(Clock base_cl, Duration time_du);
Parameter(s):
参数:
Clock base_cl – represents the base clock in which to add to the given duration.
Clock base_cl –表示要添加到给定持续时间的基本时钟。
Duration time_du – represents the duration in which to add the given clock.
持续时间time_du –表示添加给定时钟的持续时间。
Return value:
返回值:
The return type of this method is Clock, it returns Clock that ticks in entire units of the given duration.
此方法的返回类型为Clock ,它返回Clock ,该Clock在给定持续时间的整个单位内滴答。
Example:
例:
// Java program to demonstrate the example
// of tick(Clock base_cl, Duration time_du) method of Clock
import java.time.*;
public class TickOfClock {
public static void main(String args[]) {
// Instantiates two ZoneId for Accra and Asmara
ZoneId zone_1 = ZoneId.of("Africa/Accra");
ZoneId zone_2 = ZoneId.of("Africa/Asmara");
// Initialize two Clock objects
// and one Duration
Clock cl1 = Clock.system(zone_1);
Clock cl2 = Clock.system(zone_2);
Duration offset = Duration.ofNanos(20000);
// generates a new Clock from the
// given clock(cl1) with the given duration
// truncated
Clock cl_tick = cl1.tick(cl1, offset);
// Display cl1 and cl_tick instant
System.out.println("cl1.instant(): " + cl1.instant());
System.out.println("cl_tick.instant(): " + cl_tick.instant());
System.out.println();
// generates a new Clock from the
// given clock(cl2) with the given duration
// truncated
cl_tick = cl2.tick(cl2, offset);
// Display cl2 and cl_tick instant
System.out.println("cl2.instant(): " + cl2.instant());
System.out.println("cl_tick.instant(): " + cl_tick.instant());
}
}
Output
输出量
cl1.instant(): 2020-05-13T21:43:13.551129Z
cl_tick.instant(): 2020-05-13T21:43:13.598720Z
cl2.instant(): 2020-05-13T21:43:13.599785Z
cl_tick.instant(): 2020-05-13T21:43:13.600620Z
翻译自: https://www.includehelp.com/java/clock-tick-method-with-example.aspx
clock.tick