Element
Element

Reputation: 4031

ASP.net Webservice Date Parameter Timezone Offset Problem

I have an asp.net webservice with a parameter of type datetime. I have noticed asp.net seems to offset the date based on the clients timezone.

I need to disable this functionality. I simply want to pass a date (i.e. 3/15/2009) to the webservice from javascript without any timezone context.

Is my only option to change the parameter type to string then convert it server side, or is there some way to disable the deserializer from offsetting my date param ?

Upvotes: 3

Views: 2240

Answers (3)

JohnOpincar
JohnOpincar

Reputation: 5814

I had exactly this "problem" and when I thought it through, I realized that the way it worked was indeed correct, at least for my scenario. In my case, I was receiving an activeFrom and activeTo date. These can only be dates (no time part) when I actually submit these values to the processor. Our web server is in Eastern Time. I happened to be testing from a client in Central Time. My test case was failing because the value stored in the database did not match what I sent (EG 04/01/2009 01:00 vs 04/01/2009 00:00).

I thought about just stripping off the time part. This seemed OK until I considered a request coming in from a time zone east of Eastern (which would happen becuase we have clients in Thailand). I was upset because the resulting date would be one day before the date sent in the request. Then I realized, that's exactly the date I want to use.

Hopefully your scenario will work out as serendipitously as mine.

Upvotes: 0

Jonathan Parker
Jonathan Parker

Reputation: 6795

You could use a UTC date instead: http://www.java2s.com/Code/JavaScript/Date-Time/GetUTCDate.htm

Upvotes: 1

Ilya Tchivilev
Ilya Tchivilev

Reputation: 834

I'd use a string.

It kind of makes sense - a DateTime is really a "point in time", so when two clients are talking about the same DateTime, they're talking about the same INSTANT. So saying "the meteor will hit earth in 5 minutes", should adjust itself to the timezone.

Upvotes: 2

Related Questions