DateTime epochStart = new DateTime(1970, 01, 01, 0, 0, 0, 0, DateTimeKind.Utc);
TimeSpan currentTs = DateTime.UtcNow - epochStart;
ulong serverTotalSeconds = Convert.ToUInt64(currentTs.TotalSeconds);
ulong requestTotalSeconds = Convert.ToUInt64(requestTimeStamp);
ulong r = (serverTotalSeconds - requestTotalSeconds);
if (r > requestMaxAgeInSeconds)
{
return true;
}
上面的 c# 代码有时会给出错误的减去值。
例如,对于以下值
serverTotalSeconds = 1615184795
requestTotalSeconds = 1615184796
"r" is returning value 18446744073709551615
我无法理解问题的原因。有人可以指出这里到底出了什么问题吗?