如何获取pc本地时间而不是Web服务器时间。 [英] How do I get the pc local time instead of the web server time.

查看:192
本文介绍了如何获取pc本地时间而不是Web服务器时间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我有一个时间的asp页面。当在本地主机中它运行顺利但我已经上传它。我注意到时间不对。我发现这是使用Web服务器/域时间。如何根据用户当地时间计算时间?



这里我的代码:



< b>我尝试了什么:



 oras.Text = DateTime.Now.ToString(MMMM dd,yyyy hh: mm tt)

解决方案

你不能因为 DateTime.Now 在服务器上执行。



您可以使用JavaScript显示客户端的当前时间。但是您无法在服务器上访问该时间,因为JavaScript代码在客户端上执行。



如果您需要在服务器上存储时间戳,请将其作为UTC。 始终在处理日期和时间时使用UTC。



如果您想使用客户的时区显示此类时间戳,您必须存储时区信息(例如在用户数据库中)并使用它将UTC时间转换为客户端的本地时间。


hey guys i have an asp page with a time. When in local host its running smoothly but when i already uploaded it . i notice its time is wrong. and i found out that is uses the web server/domains time . how do i make the time based on the users local time?

here my code:

What I have tried:

oras.Text = DateTime.Now.ToString("MMMM dd, yyyy hh:mm tt")

解决方案

You can't because DateTime.Now is executed on the server.

You can use JavaScript to show the current time of the client. But you will not have access to that time on the server because the JavaScript code is executed on the client.

If you need to store a time stamp on the server get it there as UTC. Always use UTC when handling dates and times.

If you want to show such time stamps using the client's time zone you have to store the time zone information somewhere (e.g. in a user database) and use that to convert the UTC time to the client's local time.


这篇关于如何获取pc本地时间而不是Web服务器时间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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