Noda Time
Show / Hide Table of Contents

Class TimeProviderExtensions

Extension methods for TimeProvider.
Since 3.2.x
Availability net8.0
Inheritance
object
TimeProviderExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: NodaTime.Extensions
Assembly: NodaTime.dll
Syntax
public static class TimeProviderExtensions

Methods

GetCurrentInstant(TimeProvider)

Returns the current instant in time provided by timeProvider, as an Instant.
Since 3.2.x
Availability net8.0
Declaration
public static Instant GetCurrentInstant(this TimeProvider timeProvider)
Parameters
Type Name Description
TimeProvider timeProvider The time provider to obtain the current instant in time from. Must not be null.
Returns
Type Description
Instant The current instant in time as returned by the given time provider, expressed as an Instant.
Remarks
This is equivalent to calling GetUtcNow(), and then calling ToInstant(DateTimeOffset) on the result.

ToClock(TimeProvider)

Returns an IClock implementation which delegates to timeProvider to obtain the current instant in time.
Since 3.2.x
Availability net8.0
Declaration
public static IClock ToClock(this TimeProvider timeProvider)
Parameters
Type Name Description
TimeProvider timeProvider The time provider to obtain the current instant in time from. Must not be null.
Returns
Type Description
IClock An IClock implementation based on the given time provider.

ToZonedClock(TimeProvider)

Returns a ZonedClock which obtains the current instant in time and the local time zone from timeProvider, and uses the ISO calendar.
Since 3.2.x
Availability net8.0
Declaration
public static ZonedClock ToZonedClock(this TimeProvider timeProvider)
Parameters
Type Name Description
TimeProvider timeProvider The time provider to delegate to. Must not be null.
Returns
Type Description
ZonedClock A ZonedClock backed by the given time provider.
Remarks
The local time zone is captured from the time provider at the time of this call. If the time provider changes which time zone is reported by LocalTimeZone after this call has returned, that change will not be reflected in the returned ZonedClock.

ToZonedClock(TimeProvider, CalendarSystem)

Returns a ZonedClock which obtains the current instant in time and the local time zone from timeProvider, and uses the provided calendar system.
Since 3.2.x
Availability net8.0
Declaration
public static ZonedClock ToZonedClock(this TimeProvider timeProvider, CalendarSystem calendar)
Parameters
Type Name Description
TimeProvider timeProvider The time provider to delegate to. Must not be null.
CalendarSystem calendar The calendar system to use in the returned ZonedClock. Must not be null.
Returns
Type Description
ZonedClock A ZonedClock backed by the given time provider.
Remarks
The local time zone is captured from the time provider at the time of this call. If the time provider changes which time zone is reported by LocalTimeZone after this call has returned, that change will not be reflected in the returned ZonedClock.
In this article
Back to top Generated by DocFX