X xenophon Dec 11, 2005 #1 Does anyone have a code snippet for converting the time portion of a DateTime to seconds since midnight? Thanks.
Does anyone have a code snippet for converting the time portion of a DateTime to seconds since midnight? Thanks.
L Lloyd Dupont Dec 11, 2005 #2 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;
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;
P Peter Bromley Dec 11, 2005 #3 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; Click to expand... Use TimeOfDay as in: dt.TimeOfDay.Seconds (or TotalSeconds to include fractional part)
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; Click to expand... Use TimeOfDay as in: dt.TimeOfDay.Seconds (or TotalSeconds to include fractional part)