Soenneker.Extensions.TimeSpan 11.0.1891

Prefix Reserved
dotnet add package Soenneker.Extensions.TimeSpan --version 11.0.1891
                    
NuGet\Install-Package Soenneker.Extensions.TimeSpan -Version 11.0.1891
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Extensions.TimeSpan" Version="11.0.1891" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Extensions.TimeSpan" Version="11.0.1891" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Extensions.TimeSpan" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Extensions.TimeSpan --version 11.0.1891
                    
#r "nuget: Soenneker.Extensions.TimeSpan, 11.0.1891"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Extensions.TimeSpan@11.0.1891
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Extensions.TimeSpan&version=11.0.1891
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Extensions.TimeSpan&version=11.0.1891
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image 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 Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1891 56 12/3/2026
11.0.1890 83 12/3/2026
11.0.1889 59 12/3/2026
11.0.1888 50 12/2/2026
11.0.1887 56 12/2/2026
11.0.1886 56 12/2/2026
11.0.1885 55 12/2/2026
11.0.1884 76 12/2/2026
11.0.1883 90 12/1/2026
11.0.1882 91 12/1/2026
11.0.1881 93 12/1/2026
11.0.1880 86 12/1/2026
11.0.1879 87 12/1/2026
11.0.1878 102 11/30/2026
11.0.1877 102 11/30/2026
11.0.1876 105 11/19/2026
11.0.1875 98 11/19/2026
11.0.1874 108 11/18/2026
11.0.1873 99 11/18/2026
11.0.1872 102 11/18/2026
Loading failed

Updated Multiple NuGet packages