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

查看:529
本文介绍了如何设置DateTime值的时区(或一种)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是存储严格的UTC时间在DateTime变量中,并以ISO 8601格式输出。



要做最后一次使用.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屋!

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