How do I get the current UTC time in ulong number of minutes since 01.01.2001 00:00 in c#? I know it involves DateTime.UtcNow property but how do I get the offset in minutes?

有帮助吗?

解决方案

You can use:

ulong totalMinutes = (ulong) (DateTime.UtcNow - new DateTime(2001,1,1,0,0,0,0, DateTimeKind.Utc)).TotalMinutes;

其他提示

You can use the DateTime.UtcNow function combined to a 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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top