客户端TimeZone [英] Client TimeZone

查看:62
本文介绍了客户端TimeZone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET中没有办法检索客户端的时区(甚至是本地的时间,我会满足于此)并将其传递给服务器吗?确定网页浏览器的时区必须有一个方法

...

一定不在吗?

Is there no way in ASP.NET to retrieve the client''s timezone (or even local
time, I''d settle for that) and passing it to the server? There must be a way
of determining the timezone from which the web browser is coming from...
mustn''t there?

推荐答案

Javescript:Date.getTimezoneOffset()


您将此值传递给隐藏字段。回发后,您可以阅读

值。


" Allen Davis" <铝******** @ flex-n-gate.com>在消息中写道

新闻:OB ************* @ TK2MSFTNGP09.phx.gbl ...
Javescript: Date.getTimezoneOffset()

You pass this value to a hidden field. Upon postback, you can read the
value.

"Allen Davis" <Al********@flex-n-gate.com> wrote in message
news:OB*************@TK2MSFTNGP09.phx.gbl...
在ASP中没有办法.NET来检索客户端的时区(甚至
本地时间,我会满足于此)并将其传递给服务器?必须有一个
的方法来确定网络浏览器来自哪个时区...
一定不在吗?
Is there no way in ASP.NET to retrieve the client''s timezone (or even local time, I''d settle for that) and passing it to the server? There must be a way of determining the timezone from which the web browser is coming from...
mustn''t there?



Hi Allen,

感谢您使用Microsoft新闻组服务。根据您的描述,

您希望在ASP.NET服务器端获取客户端的UTC偏移量或

只是将此类信息传输到服务器端?我的理解是否正确?


关于这个问题,我认为你国刚的建议非常好。

虽然在dotnet框架中,但没有'没有直接接口让你获得

客户端的UTC偏移量,你可以通过一些客户端

脚本轻松完成。正如Gogang所说,使用javascript的代码

" Date.getTimezoneOffset()"并通过

隐藏输入区域将结果传输到服务器端。例如

使用这样的页面元素:


< td>

< input type =" button"值= QUOT; getclientutc" onclick =" GetClientUTC()">

< input type =" hidden" ID = QUOT; hdClientUTC" runat =" server">

< / td>


然后添加javascript函数:

< script language =" javascript">


函数GetClientUTC()

{

var now = new Date()

var offset = now.getTimezoneOffset();

document.Form1.hdClientUTC.value = offset

}

< ; / script>


请试试这个建议。如果您有任何疑问,请随时告诉我。

让我知道。


Steven Cheng

Microsoft在线支持

安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)

Hi Allen,
Thank you for using Microsoft newsgroup Service. Based on your description,
you want to get the UTC offset of the client side in ASP.NET serverside or
just transfer such info to serverside? Is my understanding correct?

As for this question, I think you Guogang''s suggestion is quite good.
Though in dotnet framework, there isn''t direct interface for you to get the
client side''s UTC offset, you can do it pretty easily via some clientside
script. Just as the Gogang said that use the javascript''s code
"Date.getTimezoneOffset()" and transfer the result to serverside by a
hidden input area. For example
use such page elements:

<td>
<input type="button" value="getclientutc" onclick="GetClientUTC()">
<input type="hidden" id="hdClientUTC" runat="server">
</td>

then add the javascript function:
<script language="javascript">

function GetClientUTC()
{
var now = new Date()
var offset = now.getTimezoneOffset();
document.Form1.hdClientUTC.value = offset
}
</script>

Please try out the suggestion. If you have any questions, please feel free
to let me know.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Steven,

感谢您的支持。它工作得很好。我已将它放在我的ASPX页面的< HEAD>

部分中,如果我使用的话,可以成功地将隐藏的

变量的值传递给服务器按钮。但是我是Java无能为力所以请跟我一起b / b
如果你愿意,请回答另一个问题。


如何执行JavaScript页面加载时的功能,所以

变量可立即用于我的服务器端代码?我尝试了一些

的东西,包括< body onload>方法但没有太多运气。


Steven Cheng [MSFT]" <,V - ****** @ online.microsoft.com>在消息中写道

news:yc ************** @ cpmsftngxa07.phx.gbl ...
Steven,

Thanks for the function. It works just fine. I''ve placed it in the <HEAD>
section of my ASPX page and can successfully pass the value of the hidden
variable to the server if I use the button. But I''m Java clueless so bear
with me and answer another question if you''re willing, please.

How can I execute that JavaScript function when the page loads so the
variable is immediately available to my server-side code? I tried a few
things including the <body onload> method but haven''t had much luck.

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:yc**************@cpmsftngxa07.phx.gbl...
Hi Allen,

感谢您使用Microsoft新闻组服务。根据您的
描述,您希望在ASP.NET服务器端获取客户端的UTC偏移量,或者只是将这些信息传输到服务器端?我的理解是否正确?

关于这个问题,我认为你国刚的建议很好。
虽然在dotnet框架中,没有直接的界面供你获取
客户端的UTC偏移量,您可以通过一些客户端脚本轻松完成。就像Gogang说使用javascript的代码
Date.getTimezoneOffset()一样并通过隐藏的输入区域将结果传输到服务器端。例如
使用这样的页面元素:

< td>
< input type =" button"值= QUOT; getclientutc" onclick =" GetClientUTC()">
< input type =" hidden" ID = QUOT; hdClientUTC"然后添加javascript函数:
< script language =" javascript">

函数GetClientUTC()
{var /> var now = new Date()
var offset = now.getTimezoneOffset();
document.Form1.hdClientUTC.value = offset
}
< / script>

请试试这个建议。如果您有任何疑问,请随时告诉我们。

Steven Cheng
Microsoft在线支持

获得安全保障! www.microsoft.com/security
(此帖已提供按原样,没有保证,也没有赋予
权利。)
Hi Allen,
Thank you for using Microsoft newsgroup Service. Based on your description, you want to get the UTC offset of the client side in ASP.NET serverside or
just transfer such info to serverside? Is my understanding correct?

As for this question, I think you Guogang''s suggestion is quite good.
Though in dotnet framework, there isn''t direct interface for you to get the client side''s UTC offset, you can do it pretty easily via some clientside
script. Just as the Gogang said that use the javascript''s code
"Date.getTimezoneOffset()" and transfer the result to serverside by a
hidden input area. For example
use such page elements:

<td>
<input type="button" value="getclientutc" onclick="GetClientUTC()">
<input type="hidden" id="hdClientUTC" runat="server">
</td>

then add the javascript function:
<script language="javascript">

function GetClientUTC()
{
var now = new Date()
var offset = now.getTimezoneOffset();
document.Form1.hdClientUTC.value = offset
}
</script>

Please try out the suggestion. If you have any questions, please feel free
to let me know.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



这篇关于客户端TimeZone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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