在 龙卷风 中设置时区

发布于 2024-10-21 15:16:12 字数 92 浏览 8 评论 0原文

人们如何处理 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伏妖词 2024-10-28 15:16:12

您必须使用 JavaScript 将 JavaScript 的时区偏移设置到 cookie 中

var userDate = new Date();
var tzOffset = userDate.getTimezoneOffset();
// Now set the cookie

You must set the timezone offset by JavaScript into cookies using JavaScript

var userDate = new Date();
var tzOffset = userDate.getTimezoneOffset();
// Now set the cookie
太阳男子 2024-10-28 15:16:12

请原谅我的愚蠢,但是为什么你要在 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.

最佳男配角 2024-10-28 15:16:12

format_date 接受 gmt_offset。这比您自己修改日期稍好一些,但对于解决所有其他时区的复杂问题并没有真正的帮助。

如果您的日期始终是过去的日期,您可以采取的一种方法是使用日期的相对格式(例如,10 分钟前),这是tornado 的format_date 的默认值。如果您需要防止日期过时,您可以将其与一些 JavaScript 结合起来。

http://www.tornadoweb.org/documentation/locale.html #tornado.locale.Locale.format_date

format_date accepts a gmt_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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文