如何在c#中获取自01.01.2001 00:00以来的ulong分钟数的当前UTC时间?我知道它涉及DateTime.UtcNow属性但是如何在几分钟内得到偏移?
答案 0 :(得分:5)
您可以使用:
ulong totalMinutes = (ulong) (DateTime.UtcNow - new DateTime(2001,1,1,0,0,0,0, DateTimeKind.Utc)).TotalMinutes;
答案 1 :(得分: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);