Soenneker.Extensions.TimeSpan
4.0.1820
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Extensions.TimeSpan --version 4.0.1820
NuGet\Install-Package Soenneker.Extensions.TimeSpan -Version 4.0.1820
<PackageReference Include="Soenneker.Extensions.TimeSpan" Version="4.0.1820" />
<PackageVersion Include="Soenneker.Extensions.TimeSpan" Version="4.0.1820" />
<PackageReference Include="Soenneker.Extensions.TimeSpan" />
paket add Soenneker.Extensions.TimeSpan --version 4.0.1820
#r "nuget: Soenneker.Extensions.TimeSpan, 4.0.1820"
#:package Soenneker.Extensions.TimeSpan@4.0.1820
#addin nuget:?package=Soenneker.Extensions.TimeSpan&version=4.0.1820
#tool nuget:?package=Soenneker.Extensions.TimeSpan&version=4.0.1820
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 | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Soenneker.Extensions.DateTime (>= 4.0.1805)
- Soenneker.Extensions.DateTimeOffsets (>= 4.0.160)
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 |
|---|---|---|
| 4.0.1825 | 0 | 9/16/2026 |
| 4.0.1824 | 0 | 9/16/2026 |
| 4.0.1823 | 0 | 9/16/2026 |
| 4.0.1822 | 28 | 9/15/2026 |
| 4.0.1821 | 38 | 9/15/2026 |
| 4.0.1820 | 74 | 9/13/2026 |
| 4.0.1819 | 79 | 9/13/2026 |
| 4.0.1818 | 83 | 9/12/2026 |
| 4.0.1817 | 79 | 9/12/2026 |
| 4.0.1816 | 76 | 9/12/2026 |
| 4.0.1815 | 81 | 9/12/2026 |
| 4.0.1814 | 80 | 9/12/2026 |
| 4.0.1813 | 77 | 9/12/2026 |
| 4.0.1812 | 93 | 9/10/2026 |
| 4.0.1811 | 95 | 9/10/2026 |
| 4.0.1810 | 83 | 9/9/2026 |
| 4.0.1809 | 94 | 9/9/2026 |
| 4.0.1808 | 88 | 9/8/2026 |
| 4.0.1807 | 98 | 9/8/2026 |
| 4.0.1806 | 96 | 9/8/2026 |
Updated NuGet packages
NuGet-Builder-Operation: 9dae5eb76ca14c72ba48a4772553906f