如何设置日期时间值的时区(或实物)?实物、时区、如何设置、日期

2023-09-04 23:39:33 作者:名字好难起

我的意思是存储严格的UTC时间的日期时间变量并输出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属性有没有setter。

I've tried to use .Kind = DateTimeKind.Utc, but it says the Kind property has no setter.

我如何明确指定的时间为UTC?是怎么样属性设置?

How do I explicitly specify the time is in UTC? How is the Kind property set?

推荐答案

虽然DateTime.Kind酒店没有一个二传手,静态方法DateTime.SpecifyKind与类指定值创建一个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