Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UTC偏移量(分钟)_C#_.net - Fatal编程技术网

C# UTC偏移量(分钟)

C# UTC偏移量(分钟),c#,.net,C#,.net,如何获得本地时间和UTC时间之间的分钟差(以C#为单位)?这将满足您的需要 (DateTime.UtcNow - DateTime.Now).TotalMinutes; 您还可以找到使用的.ToUniversalTime日期时间功能。使用: 有关详细信息,请参阅。 本文末尾的代码示例明确给出了获取本地时间和UTC时间之间差异的代码 对于那些不想点击该链接的用户,这里是该代码的摘录: // Find difference between Date.Now and Date.UtcNow

如何获得本地时间和UTC时间之间的分钟差(以C#为单位)?

这将满足您的需要

(DateTime.UtcNow - DateTime.Now).TotalMinutes;
您还可以找到使用的
.ToUniversalTime
日期时间功能。

使用:

有关详细信息,请参阅。 本文末尾的代码示例明确给出了获取本地时间和UTC时间之间差异的代码

对于那些不想点击该链接的用户,这里是该代码的摘录:

  // Find difference between Date.Now and Date.UtcNow
  date1 = DateTime.Now;
  date2 = DateTime.UtcNow;
  difference = date1 - date2;
  Console.WriteLine("{0} - {1} = {2}", date1, date2, difference);
另一个版本:

DateTimeOffset.Now.Offset.TotalMinutes

GetUtcOffset(…)
接受一个参数,因此在示例中包含该参数可能会有所帮助。比如
TimeSpan-utcOffset=TimeZoneInfo.Local.GetUtcOffset(DateTime.Now)我认为您的值颠倒了,应该是(DateTime.Now-DateTime.UtcNow);
Response.Write((DateTime.Now - DateTime.UtcNow).TotalMinutes);
DateTimeOffset.Now.Offset.TotalMinutes
DateTime localDt = DateTime.Now;
DateTime utcDt = DateTime.UtcNow;
TimeSpan localUtcDiff = utcDt.Subtract(localDt);
Console.WriteLine("The difference in minutes between local time and UTC time is " + localUtcDiff.TotalMinutes.ToString());