Soenneker.Extensions.DateTimeOffsets.Hours
11.0.175
Prefix Reserved
dotnet add package Soenneker.Extensions.DateTimeOffsets.Hours --version 11.0.175
NuGet\Install-Package Soenneker.Extensions.DateTimeOffsets.Hours -Version 11.0.175
<PackageReference Include="Soenneker.Extensions.DateTimeOffsets.Hours" Version="11.0.175" />
<PackageVersion Include="Soenneker.Extensions.DateTimeOffsets.Hours" Version="11.0.175" />
<PackageReference Include="Soenneker.Extensions.DateTimeOffsets.Hours" />
paket add Soenneker.Extensions.DateTimeOffsets.Hours --version 11.0.175
#r "nuget: Soenneker.Extensions.DateTimeOffsets.Hours, 11.0.175"
#:package Soenneker.Extensions.DateTimeOffsets.Hours@11.0.175
#addin nuget:?package=Soenneker.Extensions.DateTimeOffsets.Hours&version=11.0.175
#tool nuget:?package=Soenneker.Extensions.DateTimeOffsets.Hours&version=11.0.175
Soenneker.Extensions.DateTimeOffsets.Hours
Provides fixed-offset hour boundaries, local-hour formatting, and hour-of-day conversion between UTC and named time zones.
Installation
dotnet add package Soenneker.Extensions.DateTimeOffsets.Hours
Hour boundaries
using Soenneker.Extensions.DateTimeOffsets.Hours;
DateTimeOffset value = new(2026, 8, 29, 16, 42, 30, TimeSpan.FromHours(-4));
DateTimeOffset start = value.ToStartOfHour();
DateTimeOffset end = value.ToEndOfHour();
DateTimeOffset previousStart = value.ToStartOfPreviousHour();
DateTimeOffset nextEnd = value.ToEndOfNextHour();
| Method | Result for 16:42:30 |
|---|---|
ToStartOfHour() |
16:00:00 |
ToEndOfHour() |
One tick before 17:00:00 |
ToStartOfPreviousHour() |
15:00:00 |
ToEndOfPreviousHour() |
One tick before 16:00:00 |
ToStartOfNextHour() |
17:00:00 |
ToEndOfNextHour() |
One tick before 18:00:00 |
These methods preserve the stored offset and use fixed elapsed hours. They do not consult a named time zone or reinterpret repeated/skipped local clock hours.
Format an hour
string storedClock = value.ToHourFormat();
TimeZoneInfo eastern = TimeZoneInfo.FindSystemTimeZoneById("America/New_York");
string easternClock = value.ToTzHourFormat(eastern);
string easternHour = value.ToTzHourFormatWithTrim(eastern);
All three methods use h:mm tt with the current culture. ToHourFormat() formats the stored clock fields. ToTzHourFormat() first converts the instant to the target zone. ToTzHourFormatWithTrim() also resets local minutes and seconds to zero.
Convert a UTC hour to local time
DateTimeOffset reference = new(2026, 8, 29, 12, 0, 0, TimeSpan.Zero);
int localHour = reference.ToTzHoursFromUtc(utcHour: 18, eastern);
string localClock = reference.ToTzHourFormatFromUtc(utcHour: 18, eastern);
Both methods combine utcHour with the UTC date of reference, then convert that instant to the target zone. The integer method returns only 0–23; it discards the local date and minutes. The formatted method preserves fractional-hour offsets such as 5:30 AM.
Convert a local hour to UTC
int utcHour = reference.ToUtcHoursFromTz(tzHour: 9, eastern);
ToUtcHoursFromTz() chooses the local date in eastern that contains reference, interprets tzHour on that date, and returns only the UTC hour from 0 through 23.
If the local wall time is invalid, it advances minute-by-minute to the first valid minute. If it is ambiguous, it selects the earlier UTC instant. The returned integer does not include UTC date rollover or minutes; use a full-instant API when those details matter.
Hour arguments must be from 0 through 23.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Soenneker.Extensions.DateTimeOffsets (>= 11.0.207)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Extensions.DateTimeOffsets.Hours:
| Package | Downloads |
|---|---|
|
Soenneker.Extensions.DateTimeOffsets.Suite
A collection of all of the helpful DateTimeOffset extension methods |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.175 | 0 | 11/15/2026 |
| 11.0.173 | 176 | 11/11/2026 |
| 11.0.172 | 97 | 11/11/2026 |
| 11.0.171 | 95 | 11/11/2026 |
| 11.0.170 | 82 | 11/11/2026 |
| 11.0.169 | 120 | 11/10/2026 |
| 11.0.168 | 248 | 11/3/2026 |
| 11.0.167 | 123 | 11/3/2026 |
| 11.0.166 | 141 | 11/3/2026 |
| 11.0.165 | 158 | 10/27/2026 |
| 11.0.164 | 131 | 10/26/2026 |
| 11.0.163 | 106 | 10/26/2026 |
| 11.0.162 | 108 | 10/26/2026 |
| 11.0.161 | 110 | 10/26/2026 |
| 11.0.160 | 100 | 10/26/2026 |
| 4.0.159 | 647 | 10/15/2026 |
| 4.0.158 | 100 | 10/15/2026 |
| 4.0.157 | 106 | 10/14/2026 |
| 4.0.156 | 151 | 10/14/2026 |
| 4.0.155 | 110 | 10/14/2026 |
Update dependency Soenneker.Extensions.DateTimeOffsets to 11.0.207 (#326)