如何在asp.net C#中获取客户端PC的日期时间? [英] How to get the date time of client PC in asp.net C#?

查看:113
本文介绍了如何在asp.net C#中获取客户端PC的日期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET Web应用程序。我的托管服务器在美国。数据库存在那里。

任何人都可以浏览网站。现在我想得到客户端PC的日期时间。我将它存储在数据库中,并将其显示在浏览器中。

我有一个标签。我会在那个标签上显示它

我在谷歌搜索过它。但没找到合适的代码。

请给我C#代码。

[我正在使用asp.net,C#]

谢谢提前

Rashed

I have a ASP.NET web application. My hosting server is in USA. Database is present there.
Anyone can browse the site. Now I want to get the date time of client PC. I will store it in DB and will show it in browser.
I have a label. I will show it in that label
I have searched it in Google. But did not found proper code.
Please give me the C# code.
[I am using asp.net, C#]
Thanks in advance
Rashed

推荐答案

您无法使用C#从客户端PC获取日期/时间,因为代码隐藏在SERVER,而不是客户端。但是,您可以使用JavaScript从浏览器获取当前日期/时间。将它存储在数据库中以便在页面上显示它有什么意义?
You can't get the date/time form the client PC using C# because the code-behind is executed on the SERVER, not the client. You can, however, use JavaScript to get the current date/time from the browser. What would be the point of storing this in a database just to display it on the page?


您可以使用JavaScript获取客户端的日期时间。试试这个:



使用javascript的日期时间 [ ^ ]



收集日期&来自javascript的时间,将此日期时间值保存在 asp:HiddenField 控件中,以便可以在服务器上读取此(日期和时间)。在服务器上,在你的HiddenField的Text值上调用 Convert.ToDateTime()



希望它有帮助:)
You can use JavaScript for getting the date time of client. try this:

Date time using javascript[^]

After collecting the date & time from javascript, hold this date time value in a asp:HiddenField control so this(date & time) can be read on the server. On the server, call Convert.ToDateTime() on the Text value of your HiddenField.

hope it helps :)


如果您不想使用Javascript,可以查看此链接。它将获得客户端的Web浏览器日期和时间。



http://weblogs.asp.net/mikebosch/archive/2007/11/15/getting-the- client-browsers-date-and-time-with-asp-net.aspx [ ^ ]



为了提前警告你,这个链接在所有条件下都没有用。它解释了原因。


为了更安全,我更喜欢使用Javascript来实现这一点。如需预览此链接。



http://stackoverflow.com/questions/274826/how-to-get-client-date-and-time-in-asp-net [<一个href =http://stackoverflow.com/questions/274826/how-to-get-client-date-and-time-in-asp-nettarget =_ blanktitle =New Window> ^ ]



祝你好运
Well if you dont want to use Javascript you can have a look at this link. There it will get the client's web browser date and time.

http://weblogs.asp.net/mikebosch/archive/2007/11/15/getting-the-client-browsers-date-and-time-with-asp-net.aspx[^]

Just to warn you ahead, this link will not be helpful in all conditions though. It is explained why.

To be more safe I would prefer using the Javascript to accomplish that. For an ex look at this link.

http://stackoverflow.com/questions/274826/how-to-get-client-date-and-time-in-asp-net[^]

Good luck


这篇关于如何在asp.net C#中获取客户端PC的日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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