Noda Time
Show / Hide Table of Contents

Interface IClock

Represents a clock which can return the current time as an Instant.
Since 1.0.x
Availability net6.0, net8.0, netstandard2.0
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
public interface IClock
Remarks
IClock is intended for use anywhere you need to have access to the current time. Although it's not strictly incorrect to call SystemClock.Instance.GetCurrentInstant() directly, in the same way as you might call UtcNow, it's strongly discouraged as a matter of style for production code. We recommend providing an instance of IClock to anything that needs it, which allows you to write tests using the fake clock in the NodaTime.Testing assembly (or your own implementation).

Methods

GetCurrentInstant()

Gets the current Instant on the time line according to this clock.
Since 2.0.x
Availability net6.0, net8.0, netstandard2.0
Declaration
Instant GetCurrentInstant()
Returns
Type Description
Instant The current instant on the time line according to this clock.

Extension Methods

ClockExtensions.InBclSystemDefaultZone(IClock)
ClockExtensions.InTzdbSystemDefaultZone(IClock)
ClockExtensions.InUtc(IClock)
ClockExtensions.InZone(IClock, DateTimeZone)
ClockExtensions.InZone(IClock, DateTimeZone, CalendarSystem)

See Also

SystemClock
In this article
Back to top Generated by DocFX