Use the Add() method to add a TimeSpan to a DateTime : TimeSpan : Date Time C# Examples


C# Examples » Date Time » TimeSpan »

 

Use the Add() method to add a TimeSpan to a DateTime









    
using  System;

class  MainClass
{
    public  static  void  Main()
    {

        
        DateTime  myDateTime  =  DateTime.Parse("1/11/2004  23:10:30");

        
        TimeSpan  myTimeSpan  =  new  TimeSpan(1,  2,  4,  10);
        DateTime  myDateTime7  =  myDateTime.Add(myTimeSpan);
        Console.WriteLine("myTimeSpan  =  "  +  myTimeSpan);
        Console.WriteLine("myDateTime6.Add(myTimeSpan)  =  "  +  myDateTime7);

    }

}
    
   
  
   



Output

myTimeSpan = 1.02:04:10
myDateTime6.Add(myTimeSpan) = 03/11/2004 1:14:40 AM


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Date Time
» TimeSpan