Class ZonalClock
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.
- Author:
- Meno Hochschild
- See Also:
SystemClock.inLocalView()
,SystemClock.inZonalView(TZID)
-
Constructor Summary
ConstructorDescriptionZonalClock(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. -
Method Summary
Modifier and TypeMethodDescriptionTimeSource<?>
Gets the associated clock.Gets the associated timezone.now()
Gets the current timestamp in the associated timezone.<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.<C extends CalendarVariant<C>>
GeneralTimestamp<C>now(CalendarFamily<C> family, VariantSource variantSource, StartOfDay startOfDay)
Equivalent tonow(chronology, variantSource.getVariant(), startOfDay)
.<T extends ChronoEntity<T>>
Tnow(Chronology<T> chronology)
Gets the current timestamp in the associated timezone and given chronology.today()
Gets the current date in the associated timezone.
-
Constructor Details
-
ZonalClock
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.- Parameters:
timeSource
- source for current world time (UTC)tzid
- timezone id- Throws:
IllegalArgumentException
- if given timezone cannot be loaded
-
ZonalClock
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.- Parameters:
timeSource
- source for current world time (UTC)tzid
- timezone id- Throws:
IllegalArgumentException
- if given timezone cannot be loaded
-
ZonalClock
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.- Parameters:
timeSource
- source for current world time (UTC)tz
- timezone- Throws:
IllegalArgumentException
- if given timezone cannot be loaded- Since:
- 3.22/4.18
-
-
Method Details
-
today
Gets the current date in the associated timezone.
The result dynamically depends on the associated timezone meaning if and only if the underlying timezone is the system timezone.
- Returns:
- calendar date representing today
-
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.
- Returns:
- current local timestamp
-
now
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
- Type Parameters:
T
- generic type of chronology- Parameters:
chronology
- chronology to be used- Returns:
- current local timestamp or date in given chronology
- Throws:
IllegalArgumentException
- if given chronology requires a calendar variant- Since:
- 3.3/4.2
-
now
public <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.
- Type Parameters:
C
- generic type of chronology- Parameters:
family
- calendar family to be usedvariant
- calendar variantstartOfDay
- start of calendar day- Returns:
- current general timestamp in given chronology
- Throws:
IllegalArgumentException
- if given variant is not supported- Since:
- 3.8/4.5
-
now
public <C extends CalendarVariant<C>> GeneralTimestamp<C> now(CalendarFamily<C> family, VariantSource variantSource, StartOfDay startOfDay)Equivalent to
now(chronology, variantSource.getVariant(), startOfDay)
.- Type Parameters:
C
- generic type of chronology- Parameters:
family
- calendar family to be usedvariantSource
- source of calendar variantstartOfDay
- start of calendar day- Returns:
- current local timestamp or date in given chronology
- Throws:
IllegalArgumentException
- if given variant is not supported- Since:
- 3.8/4.5
- See Also:
now(CalendarFamily, String, StartOfDay)
-
getSource
Gets the associated clock.
- Returns:
- time source
-
getTimezone
Gets the associated timezone.
- Returns:
- timezone id
-