在unix时间戳中,小数点后应该有数字吗?

时间:2014-01-08 17:10:22

标签: c# unix-timestamp

当我使用下面的代码生成我的unix时间戳时,我在小数点后得到两个数字,如下所示:1389200512.12

这些数字应该在这里吗?他们有意义吗?那些分数是毫秒吗?

private double ConvertToTimestamp(DateTime value)
{
    //create Timespan by subtracting the value provided from
    //the Unix Epoch
    TimeSpan span = (value - new DateTime(1970, 1, 1, 0, 0, 0, 0));

    //return the total seconds (which is a UNIX timestamp)
    return Math.Round((double)span.TotalSeconds,2);
}

1 个答案:

答案 0 :(得分:0)

正如彼得所说,他们只有一秒钟,因为你调用了span.TotalSeconds。 1389200512.12不是自纪元以来的毫秒数,而是自纪元以来的秒数。如果你想要毫秒,你应该调用span.TotalMilliseconds