Write a function that takes the time as three integer arguments (hours, minutes and seconds) and returns the number of seconds since the last time the clock "struck 12." Use this function to calculate the amount of time in seconds between two times, both of which are within one 12-hour cycle of the clock.
Loading

VulpesPosted Nov 15, 2012, 12:05 PM
Hemant SrivastavaPosted Nov 15, 2012, 12:16 PM
private double FindElapsedTime(int hh, int mm, int ss)
{
// Insert today's Date and given time
DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hh, mm, ss);
DateTime dt_midNight = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
TimeSpan ts = new TimeSpan();
ts = dt-dt_midNight;
return ts.TotalSeconds;
}
If it helps you, pls mark it acepted.
Thanks