Finding the client's timezone and culture via web service

无人久伴 提交于 2019-12-04 15:50:37

Assuming your clients connect to the webservice from a browser, you can use Request.Headers["Accept-Language"] to detect the browser's culture settings.It is not possible to get the timezone directly from the server, you need some javascript on the client to compute a time difference between their local clock and GMT.

If your webservice is consumed diferently (ie. not from a browser), you will need to add these two pieces of information as parameters to your webservice methods.

Including the timezone in the request was the subject of a draft RFC here

Because this is not implemented, the only solution is to get the UTC offset in JavaScript:

// create Date object for current location
d = new Date();
// convert to msec since Jan 1 1970
localTime = d.getTime();
// obtain local UTC offset and convert to msec
localOffset = d.getTimezoneOffset() * 60000;

You're best to "ask the user" through parameters to the service. The location of the user doesn't tell you, for instance, that they are only visiting the location and are still operating on their home time; or that they are in a multi-cultural area (e.g, Switzerland) and have chosen the culture you didn't expect (French, when you were expecting German).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!