Table of Contents

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

timeZone TimeZoneInfo

The time zone returned by LocalTimeZone.

inner TimeProvider

The provider of the clock and the timers. The default is System; a FakeTimeProvider can be used in the tests.

Exceptions

ArgumentNullException

timeZone is 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

TimeZoneInfo

TimestampFrequency

Gets the frequency of GetTimestamp() of high-frequency value per second.

public override long TimestampFrequency { get; }

Property Value

long

Methods

CreateTimer(TimerCallback, object?, TimeSpan, TimeSpan)

Creates a new ITimer instance, using TimeSpan values to measure time intervals.

public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)

Parameters

callback TimerCallback

A 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.

state object

An object to be passed to the callback. This may be null.

dueTime TimeSpan

The amount of time to delay before callback is invoked. Specify InfiniteTimeSpan to prevent the timer from starting. Specify Zero to start the timer immediately.

period TimeSpan

The time interval between invocations of callback. Specify InfiniteTimeSpan to disable periodic signaling.

Returns

ITimer

The newly created ITimer instance.

Exceptions

ArgumentNullException

callback is null.

ArgumentOutOfRangeException

The number of milliseconds in the value of dueTime or period is 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()

Returns

DateTimeOffset