C# - 将日期转换为 unix 时间戳

MrS*_*Scf 5 c# datetime unix-timestamp

我正在尝试将日期转换Saturday, 22. October 1932 00:00:00为unix时间戳-1173747600000

我的代码在这里:

DateTimeOffset dt2 = new DateTimeOffset(new DateTime(1932, 10, 22)).ToUniversalTime();
long a = dt2.ToUnixTimeMilliseconds();
Run Code Online (Sandbox Code Playgroud)

我正在获取时间戳-1173751200000。我做错了什么?

Epochconverter.com正在按预期计算 unix 时间戳。查看本地时间选项,然后查看时间戳(以毫秒为单位)

Mar*_*cký 0

UNIX 时间戳是自 1970 年 1 月 1 日以来经过的秒数。这就是为什么您会在它之前的日期得到负数。