将当前时间获取为自2001年1月1日00:00起的ulong分钟数,单位为c#
从2001年1月1日00:00开始,如何获取当前UTC时间(单位:ulong)的分钟数(单位:c#)?我知道它涉及DateTime.UtcNow属性,但如何在分钟内获得偏移量?您可以使用:将当前时间获取为自2001年1月1日00:00起的ulong分钟数,单位为c#,c#,datetime,utc,C#,Datetime,Utc,从2001年1月1日00:00开始,如何获取当前UTC时间(单位:ulong)的分钟数(单位:c#)?我知道它涉及DateTime.UtcNow属性,但如何在分钟内获得偏移量?您可以使用: ulong totalMinutes = (ulong) (DateTime.UtcNow - new DateTime(2001,1,1,0,0,0,0, DateTimeKind.Utc)).TotalMinutes; 您可以使用: ulong totalMinutes = (ulong) (DateT
ulong totalMinutes = (ulong) (DateTime.UtcNow - new DateTime(2001,1,1,0,0,0,0, DateTimeKind.Utc)).TotalMinutes;
您可以使用:
ulong totalMinutes = (ulong) (DateTime.UtcNow - new DateTime(2001,1,1,0,0,0,0, DateTimeKind.Utc)).TotalMinutes;
您可以将DateTime.UtcNow函数与时间跨度结合使用:
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);
您可以将DateTime.UtcNow函数与时间跨度结合使用:
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);
到目前为止你都试了些什么?(提示-您可以从另一个
DateTime
中减去一个,得到TimeSpan
。)那么,到目前为止您尝试了什么?(提示-您可以从另一个DateTime
中减去一个TimeSpan
…)@ScottChamberlain:不在DateTime
的范围内double
在尾数中有足够的位来正确表示整个DateTime
@ScottChamberlain范围内的每一分钟数:不在DateTime
范围内double
在尾数中有足够的位来正确表示整个DateTime
范围内的每一分钟数。为什么要从刻度开始工作,而不是直接减去时间跨度呢?新的时间跨度(DateTime.UtcNow.ticks-reference.ticks)代码>步骤确实是不必要的。要么直接从刻度到分钟((DateTime.UtcNow.ticks-reference.ticks)/10000/1000/60
),要么直接减去日期时间。为什么不直接减去时间跨度而直接从刻度开始工作呢?新的时间跨度(DateTime.UtcNow.ticks-reference.ticks)代码>步骤确实是不必要的。要么直接从刻度到分钟((DateTime.UtcNow.ticks-reference.ticks)/10000/1000/60
),要么直接减去日期时间。