Use the FromDays(), FromHours(), FromMinutes(), FromSeconds(), FromMilliseconds(), and FromTicks() methods to create new TimeSpan instances : TimeSpan « Date Time « C# / CSharp Tutorial






using System;

class MainClas
{
  public static void Main()
  {
    TimeSpan myTimeSpan5 = TimeSpan.FromDays(5);
    Console.WriteLine("TimeSpan.FromDays(5) = " + myTimeSpan5);
    TimeSpan myTimeSpan6 = TimeSpan.FromHours(10);
    Console.WriteLine("TimeSpan.FromHours(10) = " + myTimeSpan6);
    TimeSpan myTimeSpan7 = TimeSpan.FromMinutes(30);
    Console.WriteLine("TimeSpan.FromMinutes(30) = " + myTimeSpan7);
    TimeSpan myTimeSpan8 = TimeSpan.FromSeconds(15);
    Console.WriteLine("TimeSpan.FromSeconds(15) = " + myTimeSpan8);
    TimeSpan myTimeSpan9 = TimeSpan.FromMilliseconds(200);
    Console.WriteLine("TimeSpan.FromMilliseconds(200) = " + myTimeSpan9);
    TimeSpan myTimeSpan10 = TimeSpan.FromTicks(500);
    Console.WriteLine("TimeSpan.FromTicks(500) = " + myTimeSpan10);
  }
}
TimeSpan.FromDays(5) = 5.00:00:00
TimeSpan.FromHours(10) = 10:00:00
TimeSpan.FromMinutes(30) = 00:30:00
TimeSpan.FromSeconds(15) = 00:00:15
TimeSpan.FromMilliseconds(200) = 00:00:00.2000000
TimeSpan.FromTicks(500) = 00:00:00.0000500








13.5.TimeSpan
13.5.1.Create a TimeSpan representing 2.5 days
13.5.2.TimeSpan calculation
13.5.3.Manual Profiler
13.5.4.Create a TimeSpan representing 1 week
13.5.5.Use the Add() method to add a TimeSpan to a DateTime
13.5.6.Use the Subtract() method to subtract a TimeSpan from a DateTime
13.5.7.Create a TimeSpan instance, specifying the hours, minutes, and seconds
13.5.8.Create a TimeSpan instance, specifying the days, hours, minutes,and seconds
13.5.9.Create a TimeSpan instance, specifying the days, hours, minutes, seconds, and milliseconds
13.5.10.Create a TimeSpan instance, specifying the number of ticks
13.5.11.Display the properties for myTimeSpan
13.5.12.Measures the time taken to add some numbers
13.5.13.Use the FromDays(), FromHours(), FromMinutes(), FromSeconds(), FromMilliseconds(), and FromTicks() methods to create new TimeSpan instances
13.5.14.Use the Add() method to add a TimeSpan instance to another
13.5.15.Use the Subtract() method to subtract a TimeSpan instance from another
13.5.16.Use the Duration() method to add two TimeSpan instances
13.5.17.Use the Negate() method to add two TimeSpan instances