如何管理Web应用程序中的时区? [英] How to manage timezones in a web application?

查看:274
本文介绍了如何管理Web应用程序中的时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能在我的网络应用程序中管理我的用户的不同时区,但我不知道从哪里开始。我必须将每个用户的本地时间保存在我的数据库中,也可以将转换转换为UTC时间,保存,然后再次进行转换以显示?或还有其他方式?例如,如果我的一个用户在当地时间预约,我必须将其转换为UTC存储在我的数据库中,然后当他需要它时,再次将其转换为当地的时间显示?顺便说一句,我正在使用Django。谢谢。

解决方案


  1. 存储日期/时间为UTC(不知道Python命令为此)


  2. 输出日期时,将其包装在帮助函数中,获取当前用户的时区首选项,然后调整偏移量的时间/日期,然后从应用程序中输出。


http://docs.python.org/library/time.html



http://docs.python.org/library/datetime.html


I wan't to manage the different timezones of my users in my web application, but I have no idea where to start. I have to save the local time of each user in my database?, or maybe make the conversion to a UTC time, save it, and then make the conversion again to show it?, or there is another way? For example, if one of my users make an appointment in his local time, I have to convert it to UTC store it in my database, and then when he need it, convert it again to his local time an show it?? By the way, I'm using Django. Thanks.

解决方案

  1. Store date/time as UTC (Not sure what the Python command for that is)

  2. When outputting dates, wrap them in a helper function that gets the current user's time zone preference, then adjust the time/date for the offset, then output it from the application.

http://docs.python.org/library/time.html

http://docs.python.org/library/datetime.html

这篇关于如何管理Web应用程序中的时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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