"Now" surfaces — PrimeTime (NodaTime) stack
The PrimeTime (NodaTime) stack adds NodaTime-first "now" projections on IPrimeClock: Instant, ZonedDateTime, LocalTime, and LocalDate — alongside the BCL surfaces from the System Clock subset.
ServiceCollection services = [];
services.AddPrimeClock();
using ServiceProvider serviceProvider = services.BuildServiceProvider();
IPrimeClock primeClock = serviceProvider.GetRequiredService<IPrimeClock>();
ScenarioConsole.WriteLine($"NowInstant: {primeClock.NowInstant}");
ScenarioConsole.WriteLine($"LocalNowInstant: {primeClock.LocalNowInstant}");
ScenarioConsole.WriteLine($"UtcNowInstant: {primeClock.UtcNowInstant}");
ScenarioConsole.WriteLine($"LocalZonedNowInstant: {primeClock.LocalZonedNowInstant}");
ScenarioConsole.WriteLine($"LocalNowTime: {primeClock.LocalNowTime}");
ScenarioConsole.WriteLine($"LocalNowDate: {primeClock.LocalNowDate}");
ScenarioConsole.WriteLine($"LocalNowDateTimeOffset: {primeClock.LocalNowDateTimeOffset:O}");
return Task.CompletedTask;
What to notice
NowInstantis the canonical NodaTime UTC instant; it is identical toUtcNowInstantand is the simplest "now" projection.LocalNowInstantis the same instant viewed in the configured local zone;LocalZonedNowInstantreturns a fullZonedDateTimethat carries zone and offset.LocalNowTime/LocalNowDatereturn NodaTimeLocalTimeandLocalDate, useful when scheduling against wall-clock components.- BCL projections like
LocalNowDateTimeOffsetremain available from the shared contract for interop with code that speaks BCL types.
Related
- Usage guide: KZDev.PrimeTime
- Concepts: Choosing a package
- API:
IPrimeClock