.net Web服务中的datetime时区转换 [英] datetime time zone conversion in .net web service

查看:46
本文介绍了.net Web服务中的datetime时区转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有日期时间参数的方法的Web服务(实际上是启用Silverlight的wcf服务,但出于所有目的和目的,它都是Web服务).该方法是从客户端调用的,该客户端可能在不同的时区.托管Web服务的服务采用太平洋标准时间,并且似乎Web服务正在将日期时间值转换为服务器时区.Web服务的目的是将datetime值与数据库中的值进行比较,但是数据库中的值基于客户端时区,因此由于进行了转换,因此无法进行比较.

I have a web service (actually a silverlight enable wcf service, but for all intents and purposes, it's a web service) with a method taking a datetime parameter. The method gets called from a client, which could be in a different time zone. The service hosting the web service is in pacific standard time, and it appears the web service is converting the date time value to the servers time zone. The intent of the web service is to compare the datetime value against a value in the database, but the value in the database is based on the clients timezone, so because of the conversion, the comparison is not working.

有什么办法可以关闭转换?

Is there any way to turn the conversion off?

推荐答案

似乎Web服务正在将日期时间值转换为服务器时区.

and it appears the web service is converting the date time value to the servers time zone.

我正在尝试确保我正确:您的Web服务方法采用DateTime类型的参数(如System.DateTime),并且正在转换传递的参数吗?

I'm trying to make sure I have this correct: your web service method takes a parameter of type DateTime (as in, System.DateTime) and is converting the passed parameter?

DateTime对象不带有隐式时区,因此Web服务确定推断本地时间的任何操作都是逻辑缺陷(至少不支持时区标准).

DateTime objects don't carry an implicit timezone, so any determination by the web service to infer local time would be a logic flaw (at least without supporting timezone criteria.)

如果您可以提供服务器和客户端代码段,则将使情况更易于诊断.

If you can supply your server and client code snippets, it would make the scenario easier to diagnose.

更新:不确定这种情况是否正确,因此请澄清:

UPDATE: Not sure if this scenario is accurate, so please clarify:

  • 客户提交的DateTime值为"CST PM 12:00:00 00:00:00 PM"
  • PST中的服务器在太平洋标准时间'10:00:00 00:00:00 PM接收/解释请求'

在这种情况下,您可以将所有数据转换为UTC时间吗?如果要执行查询查找,则意味着也将存储的数据也转换为UTC.

If this is the case, can you convert all data to UTC time? If you're executing a query lookup, this implies converting the stored data to UTC as well.

这篇关于.net Web服务中的datetime时区转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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