如何在不使用 Javascript 的情况下在 ASP.Net 中呈现给定 UTC 日期时间值的本地时间?
当您将值存储为 UTC 时,是否可以在不使用 Javascript 的情况下向用户显示当地时间?
Is it possible to display local times to users without using Javascript when you store the values as UTC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要服务器端了解客户端时区。 典型请求中没有足够的信息来做出该决定,您可以获得的最接近的是 Accept_Language 标头,它可能会给您提供线索,但几乎没有足够的用处(特别是如果客户端位于具有多个时区的国家/地区) 。
因此,您需要用户告诉您他们的时区,然后使用登录或 cookie 来存储该信息。
You would need serverside to be aware of the clients timezone. There isn't enough information in the typical request to make that determination, the closest you can get is the Accept_Language header which might give you a clue but is hardly useful enough (esp. if the client is in a country that has multiple timezones).
Hence you would need to user to tell you what their timezone is and then use a logon or cookie to store that info.
您可以在服务器端使用 vb.net、c# 或您使用的任何 .net 语言进行转换。 您将必须在某个地方转换为当地时间。
您提出了一个非常广泛的问题,没有细节,因此我无法推荐如何在服务器上执行此操作。
编辑
根据评论,我发现您遇到的问题是您想在没有javascript的情况下找出用户时区。 我总是让用户在注册时告诉我他们的时区。
一种并不完美的方法是使用地理 IP 查找服务,它会告诉您最有可能的用户位置,并为您提供比使用语言设置更好的粒度。
You could do the conversion on the serverside in vb.net, c# or whatever .net language your using. You are going to have to convert to the local time somewhere.
Your asking a very broad question with no detail so I can't recommend how to do this on the server.
Edit
Based on the comments I see the problem your having is that you want to figure out what the users timezone is without javascript. I always have the user tell me their timezone when they register.
One approach which won't be perfect would be would to be use a geo-ip lookup service that will tell you most likely where your user and give your better granularity then using the language settings.
认为这是你能做的最接近的事情:
Think this is the closest you can do: