How to set a time zone (or a Kind) of a DateTime value?(如何设置 DateTime 值的时区(或种类)?)
问题描述
我的意思是将严格的 UTC 时间存储在 DateTime 变量中,并以 ISO 8601 格式输出.
I mean to store strict UTC time in a DateTime variable and output it in ISO 8601 format.
最后我使用了.ToString("yyyy-MM-ddTHH:mm:sszzz"),它发现时区是UTC+01:00.
To do the last I've used .ToString("yyyy-MM-ddTHH:mm:sszzz"), and it has uncovered that the time zone is UTC+01:00.
我尝试使用 .Kind = DateTimeKind.Utc,但它说 Kind 属性没有设置器.
I've tried to use .Kind = DateTimeKind.Utc, but it says the Kind property has no setter.
如何明确指定时间为 UTC?Kind 属性是如何设置的?
How do I explicitly specify the time is in UTC? How is the Kind property set?
推荐答案
虽然 DateTime.Kind 属性没有设置器,但静态方法 DateTime.SpecifyKind 创建一个具有指定 Kind 值的 DateTime 实例.
While the DateTime.Kind property does not have a setter, the static method DateTime.SpecifyKind creates a DateTime instance with a specified value for Kind.
Altenatively 有几个 DateTime带有 DateTimeKind 参数的构造函数重载
Altenatively there are several DateTime constructor overloads that take a DateTimeKind parameter
这篇关于如何设置 DateTime 值的时区(或种类)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何设置 DateTime 值的时区(或种类)?


- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01