Domanda

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?

È stato utile?

Soluzione

You can use:

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

Altri suggerimenti

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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top