Javatime 简明教程
java.time.Clock Class
Introduction
java.time.Clock 类通过采用时区的方式提供当前瞬间、日期和时间访问权限。
The java.time.Clock class provides access to the current instant, date and time using a time-zone.
Class declaration
以下是对 java.io.Clock 类的声明——
Following is the declaration for java.io.Clock class −
public abstract class Clock
extends Object
Class methods
Sr.No. |
Method & Description |
1 |
boolean equals(Object obj)This method checks if this clock is equal to another clock. |
2 |
static Clock fixed(Instant fixedInstant, ZoneId zone)This method obtains a clock that always returns the same instant. |
3 |
abstract ZoneId getZone()This method gets the time-zone being used to create dates and times. |
4 |
int hashCode()This method gets a hash code for this clock. |
5 |
int instant()This method gets the current instant of the clock. |
6 |
long millis()This method gets the current millisecond instant of the clock. |
7 |
static Clock offset(Clock baseClock, Duration offsetDuration)This method obtains a clock that returns instants from the specified clock with the specified duration added. |
8 |
static Clock system(ZoneId zone)This method obtains a clock that returns the current instant using best available system clock. |
9 |
static Clock systemDefaultZone()This method obtains a clock that returns the current instant using the best available system clock, converting to date and time using the default time-zone. |
10 |
static Clock systemUTC()This method obtains a clock that returns the current instant using the best available system clock, converting to date and time using the UTC time-zone. |
11 |
static Clock tick(Clock baseClock, Duration tickDuration)This method obtains a clock that returns instants from the specified clock truncated to the nearest occurrence of the specified duration. |
12 |
static Clock tickMinutes(ZoneId zone)This method obtains a clock that returns the current instant ticking in whole minutes using best available system clock. |
13 |
static Clock tickSeconds(ZoneId zone)This method obtains a clock that returns the current instant ticking in whole seconds using best available system clock. |
14 |
static Clock withZone(ZoneId zone)This method returns a copy of this clock with a different time-zone. |