Click here to Skip to main content
15,921,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have javascript code that serializes an object with, among other thins, a date string in it (US format). It calls a web service, with this object. The web service deserializes the object, and the date string is still in US format. But then it passes the date string to a function, with the parameter as DateTime.

If the client machine has regional setting as "English (United States)", the date casts fine. But if the regional setting is "English (United Kingdom)", (and if the browser is IE), then the date casts as a UK date.

The regional setting is at the Client, and the casting is happening at the Server. So am I to assume that the regional settings are being passed in the web service protocols? And only if the browser is IE?

Thanks for your help.

Roy.
Posted

1 solution

Work with System.DataTime in your Web service, not with its string representation. In this case, calls via the service proxy will return binary time data, and the serialization and deserialization in transport will be done in culture-independent form, automatically. You should never work with serialized form directly. Your client should also use binary System.DataTime structure in all calculations, up to the very last moment when a presentation of a string on screen is needed. At this moment, use either culture-neutral, custom, of culture-specific formatting, it won't affect functionality.

—SA
 
Share this answer
 
Comments
Roy Heil 4-Oct-11 17:07pm    
SA, I agree with you, that is what the original programmer should have done. But I don't have time or resources to rewrite the application.

I do have a fix for the problem. I was just curious, when all the function at the Server has is a string, how does it know that it should parse the string as a UK date, when the Client is the one with the UK regional setting?

Thanks.
Sergey Alexandrovich Kryukov 4-Oct-11 17:27pm    
It's up to you; your situation with your resources does not affect validity of the advice, as you understand. There is no need to know regional settings, could you finally get it? only time zone is important, but you can store it separately. Even with a time zone, it's the best to do all communication in UTC and carry no timezone information. Every client can work in its own time zone using it only for final presentation of information.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900