System.TimeSpan Documentation

This document provides detailed information about the System.TimeSpan class in .NET.

What is System.TimeSpan?

The System.TimeSpan represents a duration, representing a period of time. It allows you to store time as a unique object, allowing for precise calculations and comparisons.

Key Properties

Methods

GetTimeSpan(): Returns a System.TimeSpan object.

SetTimeSpan(): Sets the start and end times of the time span.

GetUtcTime(): Returns the time span in UTC.

GetLocalTime(): Returns the time span in local time.

Subtract(): Subtracts a time span from another.

Add(): Adds a time span to another.

Example

```csharp

                System.TimeSpan startTime = new System.TimeSpan();
                System.TimeSpan end = startTime.Subtract(new DateTime(2023, 1, 1));
                Console.WriteLine($"Start Time: {startTime}");
                Console.WriteLine($"End Time: {end}");
            

This example demonstrates how to create a System.TimeSpan object, specify its start and end times, and get the duration.