在 龙卷风 中设置时区
人们如何处理 Tornado 中的时区,以便用户看到相对于其时区格式化的时间?我知道 locale.format_date 默认为 GMT,但如何根据用户设置正确的时区?
How do people handle timezones in Tornado so that users see time formatted relative to their timezone? I know there's locale.format_date which defaults to GMT, but how do I set the right timezone based on the user?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须使用 JavaScript 将 JavaScript 的时区偏移设置到 cookie 中
You must set the timezone offset by JavaScript into cookies using JavaScript
请原谅我的愚蠢,但是为什么你要在 Tornado 的上下文中根据用户来格式化日期?龙卷风是一个服务器。用户是客户。
Pardon my dimness but why do you mean to format the date based on the user in the context of Tornado? Tornado is a server. The user is a client.
format_date
接受gmt_offset
。这比您自己修改日期稍好一些,但对于解决所有其他时区的复杂问题并没有真正的帮助。如果您的日期始终是过去的日期,您可以采取的一种方法是使用日期的相对格式(例如,10 分钟前),这是tornado 的format_date 的默认值。如果您需要防止日期过时,您可以将其与一些 JavaScript 结合起来。
http://www.tornadoweb.org/documentation/locale.html #tornado.locale.Locale.format_date
format_date
accepts agmt_offset
. This is slightly better than modifying the date yourself, but doesn't really help with all the other timezone intricacies.One approach you could take if your dates are always in the past is to use relative format for dates (e.g. 10 mins ago), which is the default for tornado's format_date. You can couple that with some javascript if you need to prevent the dates from going stale.
http://www.tornadoweb.org/documentation/locale.html#tornado.locale.Locale.format_date