-->

Sunday, February 9, 2014

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

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

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

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved