java clock计时_Java Clock类| tickSeconds()方法与示例

java clock计时

Clock Class tickSeconds()方法 (Clock Class tickSeconds() method)

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

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

  • tickSeconds() method is used to get a Clock that returns the current instant that uses a suitable system clock in the given zone (zo) to tick in whole seconds.

    tickSeconds()方法用于获取一个Clock,该Clock返回当前时刻,该时刻使用给定区域(zo)中的合适系统时钟来计时整秒。

  • tickSeconds() 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.

    tickSeconds()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会出错。

  • tickSeconds() method does not throw an exception at the time of representing Clock.

    tickSeconds()方法在表示Clock时不会引发异常。

Syntax:

句法:

    public static Clock tickSeconds(ZoneId zo);

Parameter(s):

参数:

  • ZoneId zo – represents the zone to translate the clock instant to date: time.

    ZoneId zo –表示将时钟瞬间转换为日期:时间的区域。

Return value:

返回值:

The return type of this method is Clock, it returns Clock that ticks in whole seconds in the given zone.

此方法的返回类型为Clock ,它返回Clock ,它在给定区域中以整秒为单位滴答。

Example:

例:

// Java program to demonstrate the example 
// of tickSeconds(ZoneId zo) method of Clock

import java.time.*;

public class TickSecondsOfClock {
    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 
        Clock cl1 = Clock.system(zone_1);
        Clock cl2 = Clock.system(zone_2);

        // generates a new Clock that
        // returns the current instant ticking in 
        // whole seconds by using the given zone_1
        Clock cl_tick_sec = Clock.tickSeconds(zone_1);

        // Display cl1 and cl_tick_sec instant
        System.out.println("cl1.instant(): " + cl1.instant());
        System.out.println("cl_tick_sec.instant(): " + cl_tick_sec.instant());

        System.out.println();

        // generates a new Clock that
        // returns the current instant ticking in 
        // whole seconds by using the given zone_2
        cl_tick_sec = Clock.tickSeconds(zone_2);

        // Display cl2 and cl_tick_sec instant
        System.out.println("cl2.instant(): " + cl2.instant());
        System.out.println("cl_tick_sec.instant(): " + cl_tick_sec.instant());
    }
}

Output

输出量

cl1.instant(): 2020-05-13T21:58:06.625092Z
cl_tick_sec.instant(): 2020-05-13T21:58:06Z

cl2.instant(): 2020-05-13T21:58:06.674940Z
cl_tick_sec.instant(): 2020-05-13T21:58:06Z


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

java clock计时

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值