ASP.NET客户端时间 [英] ASP.NET Client Time

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

问题描述

我想是能够根据用户的当前时区中显示的时间。我将存储在UTC格式时间在我的数据库,但希望这些正常化到客户端的时区。到目前为止,似乎最可行的办法是捕捉客户的时间,然后deteremine这和当前UTC之间的差异,使用增量渲染时正常化倍。我想知道,如果有任何更直接的选项可用于检测和规范UTC时间给发出请求的客户机。

I would like to be able to display time based on the user's current time zone. I will be storing times in UTC format in my database, but wish to normalize these to the client's time zone. So far the option that seems most viable is to capture the clients time and then deteremine the difference between that and current UTC and use that delta to normalize times when rendering. I would like to know if there are any more straight forward options available to detect and normalize a UTC time to that of the requesting client's machine.

推荐答案

我会使用JavaScript dateObject.getTimezoneOffset()。即使他们的时间没有准确的设置,希望他们已经将他们的时区:

I would use the javascript dateObject.getTimezoneOffset(). Even if their time isn't set accurately, hopefully they've set their timezone:

<一个href=\"http://www.w3schools.com/jsref/jsref%5FgetTimezoneOffset.asp\">http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp

您可以使用此值来计算服务器的时间和客户端的时间之间的偏移。 (贾森有益下面评论中指出)

You can use this value to calculate an offset between the server's time and the client's time. (as Jason helpfully pointed out in a comment below)

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

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