Codectionary / Developer documentation / C#

TimeSpan Components and Totals

TimeSpan represents an elapsed time interval. Component properties such as Minutes differ from total properties such as TotalMinutes. Use a .NET 8+ console project; replace Program.cs with this C# example.

Read the syntax

TimeSpan represents an elapsed time interval. Component properties such as Minutes differ from total properties such as TotalMinutes. Use a .NET 8+ console project; replace Program.cs with this C# example.

Ninety minutes decomposes into one hour and thirty minutes. TotalMinutes expresses the entire interval in minutes.

Syntax

TimeSpan.FromMinutes(value); duration.Minutes; duration.TotalMinutes

Examples

TimeSpan Components and Totals

Use a .NET 8+ console project; replace Program.cs with this C# example.

using System;
using System.Globalization;
var duration = TimeSpan.FromMinutes(90);
Console.WriteLine(duration.Hours);
Console.WriteLine(duration.Minutes);
Console.WriteLine(duration.TotalMinutes.ToString(CultureInfo.InvariantCulture));
  1. Expected output: 1 30 90
  2. Ninety minutes decomposes into one hour and thirty minutes. TotalMinutes expresses the entire interval in minutes.
  3. Choose total properties when computing rates or timeout magnitudes.

Best practices

  • Choose total properties when computing rates or timeout magnitudes.
  • Use Stopwatch for measuring elapsed execution time.

Runtime & versions

.NET runtime. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

C# language reference

Specifications & further reading