1

如何在 c# 中获取自 01.01.2001 00:00 以来的 ulong 分钟数的当前 UTC 时间?我知道它涉及 DateTime.UtcNow 属性,但我如何在几分钟内获得偏移量?

4

2 回答 2

5

您可以使用:

ulong totalMinutes = (ulong) (DateTime.UtcNow - new DateTime(2001,1,1,0,0,0,0, DateTimeKind.Utc)).TotalMinutes;
于 2013-10-17T16:48:00.323 回答
2

您可以将 DateTime.UtcNow 函数与 TimeSpan 结合使用:

        DateTime reference = new DateTime(2001, 01, 01, 0, 0, 0, DateTimeKind.Utc);
        TimeSpan duration = new TimeSpan(DateTime.UtcNow.Ticks - reference.Ticks);
        ulong minutesCount = Convert.ToUInt64(duration.TotalMinutes);
于 2013-10-17T16:48:11.033 回答