在Web应用程序中,DateTime.Now如何知道用户的当地时间?
根据此 DateTime.Now vs. DateTime.UtcNow 您以 UTC 存储日期时间信息并将其显示为 DateTime.Now 给用户。如果是在 Web 应用程序上,DateTime.Now 如何了解用户的位置并相应地调整 UTC 时间?位置是从用户传入的标头信息推断出来的吗?
According to this DateTime.Now vs. DateTime.UtcNow you store date time information in UTC and show it to user as DateTime.Now. If it is on web application, how does DateTime.Now know about user's location and adjusts UTC time accordingly? Is location inferred from header information that user passes in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DateTime.Now 不知道用户的位置并进行调整。它基于站点运行的服务器。
DateTime.Now does not know the user's location and adjust for it. It is based off the server the site is running on.
正如布莱克所说,事实并非如此。
如果服务器正在计算最终用户的当前时间,则它必须基于用户提供的信息。否则,您通常会使用 JavaScript 根据本地计算机的时钟提供当前日期/时间参考。
As Blake said, it doesn't.
If a server is calculating the current time for the end user, it must be based on information that user has provided. Otherwise, you typically would use javascript to provide the current date/time reference based on the local machine's clock.
DateTime.Now
根据服务器而不是客户端返回当前时间。DateTime.Now
returns the current time according to the server, not the client.