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计时