public final class ZonalClock extends Object
Represents a clock which yields the current local time according to a timezone.
This class is immutable as long as the underlying implementations of time source and time zone are.
SystemClock.inLocalView()
,
SystemClock.inZonalView(TZID)
Constructor and Description |
---|
ZonalClock(TimeSource<?> timeSource,
String tzid)
Constructs a new clock which can yield the current local time in
given timezone.
|
ZonalClock(TimeSource<?> timeSource,
Timezone tz)
Constructs a new clock which can yield the current local time in
given timezone.
|
ZonalClock(TimeSource<?> timeSource,
TZID tzid)
Constructs a new clock which can yield the current local time in
given timezone.
|
Modifier and Type | Method and Description |
---|---|
Moment |
currentMoment()
Equivalent to the expression
now().inStdTimezone() . |
TimeSource<?> |
getSource()
Gets the associated clock.
|
TZID |
getTimezone()
Gets the associated timezone.
|
PlainTimestamp |
now()
Gets the current timestamp in the associated timezone.
|
<C extends CalendarVariant<C>> |
now(CalendarFamily<C> family,
String variant,
StartOfDay startOfDay)
Gets the current timestamp in the associated timezone and given chronology taking into account
given calendar variant and start of day.
|
<C extends CalendarVariant<C>> |
now(CalendarFamily<C> family,
VariantSource variantSource,
StartOfDay startOfDay)
Equivalent to
now(chronology, variantSource.getVariant(), startOfDay) . |
<T extends ChronoEntity<T>> |
now(Chronology<T> chronology)
Gets the current timestamp in the associated timezone and given chronology.
|
PlainDate |
today()
Ermittelt das aktuelle Datum in der assoziierten Zeitzone.
|
public ZonalClock(TimeSource<?> timeSource, TZID tzid)
Constructs a new clock which can yield the current local time in given timezone.
Most users have no need to directly call this constructor. It is
mainly designed for being called by dedicated expressions like
SystemClock.inZonalView(tzid)
etc.
timeSource
- source for current world time (UTC)tzid
- timezone idIllegalArgumentException
- if given timezone cannot be loadedpublic ZonalClock(TimeSource<?> timeSource, String tzid)
Constructs a new clock which can yield the current local time in given timezone.
Most users have no need to directly call this constructor. It is
mainly designed for being called by dedicated expressions like
SystemClock.inZonalView(tzid)
etc.
timeSource
- source for current world time (UTC)tzid
- timezone idIllegalArgumentException
- if given timezone cannot be loadedpublic ZonalClock(TimeSource<?> timeSource, Timezone tz)
Constructs a new clock which can yield the current local time in given timezone.
Most users have no need to directly call this constructor. It is
mainly designed for being called by dedicated expressions like
SystemClock.inLocalView()
etc.
timeSource
- source for current world time (UTC)tz
- timezoneIllegalArgumentException
- if given timezone cannot be loadedpublic PlainDate today()
Ermittelt das aktuelle Datum in der assoziierten Zeitzone.
Das Ergebnis hängt genau dann dynamisch von der assoziierten Zeitzone ab, wenn die System-Zeitzone vorliegt.
public PlainTimestamp now()
Gets the current timestamp in the associated timezone.
The result dynamically depends on the associated timezone meaning if and only if the underlying timezone is the system timezone.
public <T extends ChronoEntity<T>> T now(Chronology<T> chronology)
Gets the current timestamp in the associated timezone and given chronology.
The result always dynamically depends on the associated timezone meaning if the underlying timezone data change then the result will also change by next call.
Code example:
System.out.println(SystemClock.inLocalView().now(PlainTime.axis())); // local wall time
T
- generic type of chronologychronology
- chronology to be usedIllegalArgumentException
- if given chronology requires a calendar variantpublic <C extends CalendarVariant<C>> GeneralTimestamp<C> now(CalendarFamily<C> family, String variant, StartOfDay startOfDay)
Gets the current timestamp in the associated timezone and given chronology taking into account given calendar variant and start of day.
The result always dynamically depends on the associated timezone meaning if the underlying timezone data change then the result will also change by next call.
Code example:
HijriCalendar hijriDate = CLOCK.now( HijriCalendar.family(), HijriCalendar.VARIANT_UMALQURA, StartOfDay.EVENING) .toDate(); System.out.println(hijriDate); // AH-1436-10-02[islamic-umalqura]
Note that this example is even true if the current timestamp is 2015-07-17T18:00 which would normally map to AH-1436-10-01 (if the clock time is not considered). Reason is that the islamic day starts on the evening of the previous day.
C
- generic type of chronologyfamily
- calendar family to be usedvariant
- calendar variantstartOfDay
- start of calendar dayIllegalArgumentException
- if given variant is not supportedpublic <C extends CalendarVariant<C>> GeneralTimestamp<C> now(CalendarFamily<C> family, VariantSource variantSource, StartOfDay startOfDay)
Equivalent to now(chronology, variantSource.getVariant(), startOfDay)
.
C
- generic type of chronologyfamily
- calendar family to be usedvariantSource
- source of calendar variantstartOfDay
- start of calendar dayIllegalArgumentException
- if given variant is not supportednow(CalendarFamily, String, StartOfDay)
public Moment currentMoment()
Equivalent to the expression now().inStdTimezone()
.
For performance reasons, it is usually better to directly call SystemClock.currentMoment()
.
However, this method is designed for mobile platforms where users have adjusted the clock to compensate
outdated or wrong device timezone data, see also SystemClock.inPlatformView()
.
public TimeSource<?> getSource()
Gets the associated clock.
public TZID getTimezone()
Gets the associated timezone.
Copyright © 2014–2018. All rights reserved.