Time elapsed since midnight in C#

  • Thread starter Thread starter Zach
  • Start date Start date
Z

Zach

I seem to remember that there is a method
for establishing time elapsed since midnight,
which is it?

Thank you.
Zach.
 
Hi Zach,

Um, time elapsed since midnight would be the time in hours, minutes,
seconds on a 24 hour system.
I believe the DateTime object uses a 24 hour clock so this code should be
valid on any system.

DateTime d = DateTime.Now;
MessageBox.Show(d.Hour + " " + d.Minute + " " + d.Second);
 
Zach said:
I seem to remember that there is a method
for establishing time elapsed since midnight,
which is it?

Thank you.
Zach.

TimeSpan sinceMidnight = DateTime.Now - DateTime.Today;
double secs = sinceMidnight.TotalSeconds;



Hans Kesting
 
Hans Kesting said:
TimeSpan sinceMidnight = DateTime.Now - DateTime.Today;
double secs = sinceMidnight.TotalSeconds;

or just

double secs = DateTime.Now.TimeOfDay.TotalSeconds;
 
Back
Top