Why does DateTime to Unix time use a double instead of an integer?
Posted
by
Earlz
on Stack Overflow
See other posts from Stack Overflow
or by Earlz
Published on 2011-03-05T21:24:16Z
Indexed on
2011/03/05
23:24 UTC
Read the original article
Hit count: 196
I'm needing to convert a DateTime to a Unix timestamp. So I googled it looking for some example code
In just about all the results I see, they use double
as the return for such a function, even when explicitly using floor
to convert it to an integer. Unix timestamps are always integers. So what problem is there with using either long
or int
instead of double?
static double ConvertToUnixTimestamp(DateTime date)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan diff = date - origin;
return Math.Floor(diff.TotalSeconds);
}
© Stack Overflow or respective owner