如何设置DateTime值的时区(或一种)? [英] How to set a time zone (or a Kind) of a DateTime value?
问题描述
要做最后一次使用.ToString(yyyy -MM-ddTHH:mm:sszzz),并且已经发现时区是UTC + 01:00。
我试图使用.Kind = DateTimeKind.Utc,但它表示Kind属性没有setter。
如何明确指定时间是UTC?
虽然DateTime.Kind属性没有setter,静态方法 DateTime.SpecifyKind 创建一个DateTime具有指定值的实例。
还有几个 DateTime构造函数重载采用DateTimeKind参数
I mean to store strict UTC time in a DateTime variable and output it in ISO 8601 format.
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.
I've tried to use .Kind = DateTimeKind.Utc, but it says the Kind property has no setter.
How do I explicitly specify the time is in UTC? How is the Kind property set?
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 there are several DateTime constructor overloads that take a DateTimeKind parameter
这篇关于如何设置DateTime值的时区(或一种)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!