如何设置 DateTime 值的时区(或种类)? [英] How to set a time zone (or a Kind) of a DateTime value?

查看:38
本文介绍了如何设置 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 值的时区(或种类)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆