Time Conversion to Seconds?

  • Thread starter Thread starter xenophon
  • Start date Start date
X

xenophon

Does anyone have a code snippet for converting the time portion of a
DateTime to seconds since midnight?

Thanks.
 
what about something like that:

// warning: pseudo code from the back of my mind

DateTime dt0;
DateTime dt = new DateTime(dt0.Year, dt0.Month, dt0.Day, 0, 0, 0);
TimeSpan ts = dt - dt0;
return ts.Seconds;
 
Lloyd said:
what about something like that:

// warning: pseudo code from the back of my mind

DateTime dt0;
DateTime dt = new DateTime(dt0.Year, dt0.Month, dt0.Day, 0, 0, 0);
TimeSpan ts = dt - dt0;
return ts.Seconds;
Use TimeOfDay as in:

dt.TimeOfDay.Seconds (or TotalSeconds to include fractional part)
 
Back
Top