Search

Sunday, February 9, 2014
0 comments

How to get Total traveling time of Train in c# programming

5:15 AMSunday, February 9, 2014
Its a very easy concepts, finding traveling time, which is travel by a train. Suppose your train arrival Date and time is 2/9/2014  10:47:00 PM and departure date time is 2/8/2014 6:32:00 PM . Now, you want to get total traveling time. Use TimeSpan Structure for getting elapsed time. Lets take an simple example.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime departure = new DateTime(2014, 2, 8, 18, 32, 0);
            DateTime arrival = new DateTime(2014, 2, 9, 22, 47, 0);
            TimeSpan travelTime = arrival - departure;
            Console.WriteLine("{0} - {1} = {2}", arrival, departure, travelTime);
            Console.ReadKey();
        }
    }
}

Code generate the following output

How to get Total traveling time of Train in c# programming

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top