get client machine timezone in asp.net mvc

后端 未结 3 1947
旧巷少年郎
旧巷少年郎 2021-01-01 06:59

How to get the time zone id (ex.: Central Standard Time) of the client machine in asp.net mvc?

3条回答
  •  既然无缘
    2021-01-01 07:31

    That information is not sent to the server, so there is not trivial way to do it. One option would be to look up the IP in a Geolocation Database. http://www.ip2location.com/ is one.

    You can also do a ajax postback using the javascript Date.getTimezoneOffset().

    $.get('/User/SetTimeZone' + Date.getTimezoneOffset());
    

    and store this in the session or with the user data.

提交回复
热议问题