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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top