从服务器端在 HttpRequest 中查找时区 [英] Finding timezone in HttpRequest from server side

查看:70
本文介绍了从服务器端在 HttpRequest 中查找时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过 var dateHeaders = HttpContext.Current.Request.Headers["Date"] 但它包含 null,显然没有这样的键.

谁能告诉我在哪里可以找到当前客户端的时区?

参考:.

I have tried var dateHeaders = HttpContext.Current.Request.Headers["Date"] but it contains null, apparently there is no such key.

Can anyone tell me where else can I find the time-zone of the current client?

Reference: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

I want to parse dateTime to the following format:

Sun Nov 14 43745 00:00:00 GMT+0200 (Jerusalem Standard Time)

btw, what's the '43745' part?

解决方案

The date header is not one that is sent in standard http requests. I just ran a quick check with fiddler using both IE and Firefox and didn't see the date header sent on any requests.

The best that you can do on the server is get the user's culture, but this will only help with the date format, not the timezone.

However, you can get the information from javascript using getTimezoneOffset. For example:

var timeNow = new Date();
var timezone = timeNow.getTimezoneOffset() / 60 * (-1);

There is an excellent description here.

这篇关于从服务器端在 HttpRequest 中查找时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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