简体   繁体   English

在WCF服务返回的DataSet中保留DateTime值

[英]Preserving DateTime values in DataSet returned from WCF service

I am returning a DataSet from a WCF web service to the client. 我正在从WCF Web服务向客户端返回数据集。 The server and client are in different time zones. 服务器和客户端位于不同的时区。 Some DateTime columns are the server's local time, others are in UTC. 一些DateTime列是服务器的本地时间,其他列是UTC。

The problem is the DateTime values in the returned DataSet get converted to client's local time. 问题是返回的DataSet中的DateTime值被转换为客户端的本地时间。 Is there a way to preserve the DateTime values that the server is sending back? 有没有办法保留服务器发回的DateTime值?

返回DateTimeOffset

You should always use UTC relative datatimes. 您应该始终使用UTC相对数据时间。 Make sure that the Kind property is set to DateTimeKind.Utc . 确保Kind属性设置为DateTimeKind.Utc If not then WCF tries to convert to the local timezone any datetime fields! 如果不是,那么WCF尝试将任何datetime字段转换为本地时区!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM