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

java clock计时

Clock Class fixed()方法 (Clock Class fixed() method)

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

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

  • fixed() method is used to represent this Clock as a fixed instant (i.e. it returns the same instant that is similar to this Clock).

    fixed()方法用于将该时钟表示为固定时刻(即,它返回与该Clock类似的同一时刻)。

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

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

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

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

Syntax:

句法:

    public static Clock fixed(Instant f_in, ZoneId zo);

Parameter(s):

参数:

  • Instant f_in – represents the fixed instant to use as this Clock.

    Instant f_in –表示用作此Clock的固定瞬间。

  • ZoneId zo – represents the time zone that is used to convert the fixed instant to date: time.

    ZoneId zo –表示用于将固定时刻转换为日期:时间的时区。

Return value:

返回值:

The return type of this method is Clock, it returns the Clock object that have the same instant values.

此方法的返回类型为Clock ,它返回具有相同即时值的Clock对象。

Example:

例:

// Java program to demonstrate the example 
// of fixed(Instant f_in, ZoneId zo) method of Clock

import java.time.*;

public class FixedOfClock {
    public static void main(String args[]) {
        // Creating a fixed Instant   
        Instant in = Instant.ofEpochSecond(2500);

        // Instantiates two ZoneId for Accra 
        // and Asmara
        ZoneId zone_1 = ZoneId.of("Africa/Accra");
        ZoneId zone_2 = ZoneId.of("Africa/Asmara");

        // generates a Clock that returns the same 
        // instant for the given zone zone_1
        Clock cl_fixed = Clock.fixed( in , zone_1);

        // Display cl_fixed instant
        System.out.println("Clock.fixed(in,zone_1): " + cl_fixed.toString());

        // generates a Clock that returns the same 
        // instant for the given zone zone_2
        cl_fixed = Clock.fixed( in , zone_2);

        // Display cl_fixed instant
        System.out.println("Clock.fixed(in,zone_2): " + cl_fixed.toString());
    }
}

Output

输出量

Clock.fixed(in,zone_1): FixedClock[1970-01-01T00:41:40Z,Africa/Accra]
Clock.fixed(in,zone_2): FixedClock[1970-01-01T00:41:40Z,Africa/Asmara]


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

java clock计时

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值