如何在 C# 中创建 unix 时间戳?(例如 2012-10-10 14:00:00 -> 1349877600)
问问题
27610 次
2 回答
39
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).ToLocalTime());
//return the total seconds (which is a UNIX timestamp)
return (double)span.TotalSeconds;
}
于 2012-10-10T14:38:07.177 回答
-1
DateTime.UtcNow - new DateTime(2012,10,10,14,0,0)).TotalSeconds
于 2012-10-10T14:39:13.960 回答