Soenneker.Extensions.TimeSpan
11.0.1870
Prefix Reserved
dotnet add package Soenneker.Extensions.TimeSpan --version 11.0.1870
NuGet\Install-Package Soenneker.Extensions.TimeSpan -Version 11.0.1870
<PackageReference Include="Soenneker.Extensions.TimeSpan" Version="11.0.1870" />
<PackageVersion Include="Soenneker.Extensions.TimeSpan" Version="11.0.1870" />
<PackageReference Include="Soenneker.Extensions.TimeSpan" />
paket add Soenneker.Extensions.TimeSpan --version 11.0.1870
#r "nuget: Soenneker.Extensions.TimeSpan, 11.0.1870"
#:package Soenneker.Extensions.TimeSpan@11.0.1870
#addin nuget:?package=Soenneker.Extensions.TimeSpan&version=11.0.1870
#tool nuget:?package=Soenneker.Extensions.TimeSpan&version=11.0.1870
Soenneker.Extensions.TimeSpan
Format durations and convert clock-time TimeSpan values across time zones.
Installation
dotnet add package Soenneker.Extensions.TimeSpan
Format a duration
using Soenneker.Extensions.TimeSpan;
TimeSpan elapsed = TimeSpan.FromMinutes(65);
string compact = elapsed.ToDisplayFormat(); // "1h 5m"
string readable = elapsed.ToDisplayFormat(false); // "1 hour, 5 minutes"
ToDisplayFormat() chooses the two most significant units and treats a year as 365 days. Durations below one millisecond, including negative values, return "0s".
For fixed component formats, ToHourMinuteSecondString() uses hh:mm:ss and wraps hours after 23; ToMinuteSecondString() uses mm:ss and wraps minutes after 59. These are component displays, not total-hour or total-minute formats.
Work with times of day
TimeSpan localClock = new(9, 30, 0);
DateTime utcInstant = DateTime.UtcNow;
TimeSpan utcClock = localClock.ToUtcFromTz(utcInstant, timeZone);
TimeSpan roundTrip = utcClock.ToTzFromUtc(utcInstant, timeZone);
The conversion helpers interpret the TimeSpan as a clock time, apply the zone offset at the supplied instant (including daylight-saving and fractional-hour offsets), and normalize the result into [00:00:00, 24:00:00). Pass a UTC DateTime/DateTimeOffset that represents the date whose offset you need; a time zone cannot be converted correctly without a date.
ToShortTime() also treats the value as a clock time, normalizes it to one day, and emits an invariant 12-hour value such as "9:30 AM".
Test a clock range
bool open = new TimeSpan(23, 0, 0).IsBetween(
start: new TimeSpan(22, 0, 0),
end: new TimeSpan(2, 0, 0)); // true
IsBetween() is start-inclusive and end-exclusive and supports ranges that cross midnight. Equal start and end values represent an empty range, not a full day.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Soenneker.Extensions.DateTimeOffsets (>= 11.0.207)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.1870 | 0 | 11/14/2026 |
| 11.0.1869 | 69 | 11/11/2026 |
| 11.0.1868 | 58 | 11/11/2026 |
| 11.0.1866 | 75 | 11/11/2026 |
| 11.0.1865 | 79 | 11/11/2026 |
| 11.0.1864 | 74 | 11/11/2026 |
| 11.0.1863 | 73 | 11/10/2026 |
| 11.0.1862 | 72 | 11/10/2026 |
| 11.0.1861 | 203 | 11/3/2026 |
| 11.0.1860 | 94 | 11/3/2026 |
| 11.0.1859 | 89 | 11/3/2026 |
| 11.0.1858 | 122 | 10/27/2026 |
| 11.0.1857 | 107 | 10/26/2026 |
| 11.0.1856 | 97 | 10/26/2026 |
| 11.0.1855 | 96 | 10/26/2026 |
| 11.0.1854 | 99 | 10/26/2026 |
| 11.0.1853 | 95 | 10/26/2026 |
| 4.0.1851 | 468 | 10/15/2026 |
| 4.0.1850 | 116 | 10/14/2026 |
| 4.0.1849 | 106 | 10/14/2026 |
Update dependency Soenneker.Extensions.DateTimeOffsets to 11.0.207 (#2310)