开发者

Setting timezone in Tornado

How do peo开发者_Go百科ple 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?


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

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


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 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜