Class ZonedTimeProvider
- Namespace
- Arc4u
- Assembly
- Arc4u.dll
A TimeProvider whose LocalTimeZone is a given time zone instead of the time zone of the machine. The clock, the timestamps and the timers come from an inner provider (System by default).
public sealed class ZonedTimeProvider : TimeProvider
- Inheritance
-
ZonedTimeProvider
- Inherited Members
- Extension Methods
Examples
var brussels = new ZonedTimeProvider(TimeZoneInfo.FindSystemTimeZoneById("Europe/Brussels"));
var now = brussels.GetLocalNow(); // 2026-10-29 11:00 +01:00 when it is 10:00 UTC
Remarks
Use it to display or compute dates in the time zone of the business, whatever the time zone of the server or of the browser.
GetLocalNow() then returns the current time in that time zone.
Register it with AddZonedTimeProvider.
Constructors
ZonedTimeProvider(TimeZoneInfo, TimeProvider?)
Initializes a new instance of the ZonedTimeProvider class.
public ZonedTimeProvider(TimeZoneInfo timeZone, TimeProvider? inner = null)
Parameters
timeZoneTimeZoneInfoThe time zone returned by LocalTimeZone.
innerTimeProviderThe provider of the clock and the timers. The default is System; a
FakeTimeProvidercan be used in the tests.
Exceptions
- ArgumentNullException
timeZoneis null.
Properties
LocalTimeZone
Gets a TimeZoneInfo object that represents the local time zone according to this TimeProvider's notion of time.
public override TimeZoneInfo LocalTimeZone { get; }
Property Value
TimestampFrequency
Gets the frequency of GetTimestamp() of high-frequency value per second.
public override long TimestampFrequency { get; }
Property Value
Methods
CreateTimer(TimerCallback, object?, TimeSpan, TimeSpan)
public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
Parameters
callbackTimerCallbackA delegate representing a method to be executed when the timer fires. The method specified for callback should be reentrant, as it may be invoked simultaneously on two threads if the timer fires again before or while a previous callback is still being handled.
stateobjectAn object to be passed to the
callback. This may be null.dueTimeTimeSpanThe amount of time to delay before
callbackis invoked. Specify InfiniteTimeSpan to prevent the timer from starting. Specify Zero to start the timer immediately.periodTimeSpanThe time interval between invocations of
callback. Specify InfiniteTimeSpan to disable periodic signaling.
Returns
Exceptions
- ArgumentNullException
callbackis null.- ArgumentOutOfRangeException
The number of milliseconds in the value of
dueTimeorperiodis negative and not equal to Infinite, or is greater than MaxValue.
GetTimestamp()
Gets the current high-frequency value designed to measure small time intervals with high accuracy in the timer mechanism.
public override long GetTimestamp()
Returns
- long
A long integer representing the high-frequency counter value of the underlying timer mechanism.
GetUtcNow()
Gets a DateTimeOffset value whose date and time are set to the current Coordinated Universal Time (UTC) date and time and whose offset is Zero, all according to this TimeProvider's notion of time.
public override DateTimeOffset GetUtcNow()