GeezerVison is showing docs.oracle.com — Clock (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.time
Class Clock
-
-
Constructor Summary
Constructors
| Modifier |
Constructor |
Description |
protected |
Clock() |
Constructor accessible by subclasses.
|
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
| Modifier and Type |
Method |
Description |
boolean |
equals(Object obj) |
Checks if this clock is equal to another clock.
|
static Clock |
fixed(Instant fixedInstant,
ZoneId zone) |
Obtains a clock that always returns the same instant.
|
abstract ZoneId |
getZone() |
Gets the time-zone being used to create dates and times.
|
int |
hashCode() |
A hash code for this clock.
|
abstract Instant |
instant() |
Gets the current instant of the clock.
|
long |
millis() |
Gets the current millisecond instant of the clock.
|
static Clock |
offset(Clock baseClock,
Duration offsetDuration) |
Obtains a clock that returns instants from the specified clock with the
specified duration added
|
static Clock |
system(ZoneId zone) |
Obtains a clock that returns the current instant using best available
system clock.
|
static Clock |
systemDefaultZone() |
Obtains a clock that returns the current instant using the best available
system clock, converting to date and time using the default time-zone.
|
static Clock |
systemUTC() |
Obtains a clock that returns the current instant using the best available
system clock, converting to date and time using the UTC time-zone.
|
static Clock |
tick(Clock baseClock,
Duration tickDuration) |
Obtains a clock that returns instants from the specified clock truncated
to the nearest occurrence of the specified duration.
|
static Clock |
tickMinutes(ZoneId zone) |
Obtains a clock that returns the current instant ticking in whole minutes
using best available system clock.
|
static Clock |
tickSeconds(ZoneId zone) |
Obtains a clock that returns the current instant ticking in whole seconds
using best available system clock.
|
abstract Clock |
withZone(ZoneId zone) |
Returns a copy of this clock with a different time-zone.
|
-
-
Method Detail
-
millis
public long millis()
Gets the current millisecond instant of the clock.
This returns the millisecond-based instant, measured from 1970-01-01T00:00Z (UTC).
This is equivalent to the definition of System.currentTimeMillis().
Most applications should avoid this method and use Instant to represent
an instant on the time-line rather than a raw millisecond value.
This method is provided to allow the use of the clock in high performance use cases
where the creation of an object would be unacceptable.
The default implementation currently calls instant().
- Returns:
- the current millisecond instant from this clock, measured from
the Java epoch of 1970-01-01T00:00Z (UTC), not null
- Throws:
DateTimeException - if the instant cannot be obtained, not thrown by most implementations
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|