简体   繁体   English

DateTime.kind 属性

[英]DateTime.kind property

Have a small doubt with the DateTime.kind property.DateTime.kind属性有一点疑问。 Documentation says that kind property have three fields Unspecified, Local, and Utc to show how the datetime object is represented.文档说kind属性具有三个字段Unspecified, Local, and Utc ,以显示日期时间 object 的表示方式。

DateTime dt1 = DateTime.Now;
Console.WriteLine(dt1.Kind);

Which shows "Local" but in some microsoft documentation I red that system date and time that Windows maintains is UTC rather than local time.其中显示“本地”,但在一些微软文档中,我将 Windows 维护的系统日期和时间标记为 UTC 而不是本地时间。

If that is the case then the above WriteLine should output it as UTC rather than Local?如果是这种情况,那么上面的WriteLine应该 output 它是 UTC 而不是 Local?

Any idea?任何想法?

--Rahul ——拉胡尔

DateTime.Now is meant to retrieve the current local time. DateTime.Now旨在检索当前本地时间。 DateTime.UtcNow retrieves the current UTC time. DateTime.UtcNow检索当前 UTC 时间。

Note that this is unrelated to how Windows itself stores the time.请注意,这与 Windows 本身如何存储时间无关。 I believe it stores the current time in UTC, but also keeps track of the current time zone, so it can display the appropriate local time.我相信它以 UTC 存储当前时间,但也跟踪当前时区,因此它可以显示适当的本地时间。 I believe this is what DateTime.Now does as well.我相信这也是DateTime.Now所做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM