If you're not interested in hrs/mins/secs/ms you can just use the override
that leaves those out:
DateTime startTime = new DateTime(1970,1,1);
I suppose that if you don't need currTime for anything else you could save
one intermediate step:
UInt32 time_t = Convert.ToUInt32(Math.Abs((DateTime.Now -
startTime).TotalSeconds));
.... although possibly the compiler may optimize that in anyhow. And of
course if you're doing this repeatedly, startTime should be calculated once,
outside the loop.
Why use Math.Abs()? If startTime will always be Jan 1 1970, the result of
the subtraction will always be positive unless you plan to set your system
clock prior to Jan 1 1970:
UInt32 time_t = Convert.ToUInt32((DateTime.Now - startTime).TotalSeconds);
--Bob
"John J. Hughes II" <no@invalid.com> wrote in message
news:O%****************@TK2MSFTNGP09.phx.gbl...
Is there a better way of doing this?
DateTime startTime = new DateTime(1970,1,1,0,0,0,0);
TimeSpan currTime = DateTime.Now - startTime;
UInt32 time_t = Convert.ToUInt32(Math.Abs(currTime.TotalSeconds));
Regards,
John