C# TimeSpan ToString()

Description

TimeSpan ToString() converts the value of the current TimeSpan object to its equivalent string representation.

Syntax

TimeSpan.ToString() has the following syntax.


public override string ToString()

Returns

TimeSpan.ToString() method returns The string representation of the current TimeSpan value.

Example

The following example displays the strings returned by calling the ToString method with a number of TimeSpan values.


using System;/*ww w .jav a  2 s  .c o m*/

public class ToString
{
   public static void Main()
   {
      TimeSpan span;

      // Initialize a time span to zero.
      span = TimeSpan.Zero;
      Console.WriteLine(span);

      // Initialize a time span to 14 days.
      span = new TimeSpan(-14, 0, 0, 0, 0);
      Console.WriteLine(span);

   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version