1
我需要解析来自用户输入的日期/时间字符串,并将其转换为基于字符串所不具备相应的时区信息为datetime.strptime()
UTC(有什么建议?)。有没有一个简单的方法来做到这一点?用户指定的日期时间
理想的情况下,在谷歌应用程序引擎,我想如果可能的话还tzinfo从浏览器抢本地时间。
timezone_string = "GMT-0800"
fields = ("eventstartmonth","eventstartday", "eventstartyear", "eventstarttimehour", "eventstarttimeampm")
date_string = '_'.join(map(lambda x: self.request.get(x), fields))
# date_string = "01_11_2000_1:35_PM"
dt = datetime.datetime.strptime(date_string, "%m_%d_%Y_%I:%M_%p")
# how to convert dt into a tz-aware datetime, and then to UTC
[On GAE,我如何根据正确的客户端TimeZone显示日期?](http://stackoverflow.com/questions/868708/on-gae-how-may-i-showa-a-日期根据到右客户时区) – msw 2010-09-11 22:21:17
接近,这有一些相关的信息(谢谢),但不完全。我可以用tzinfo策略多用一点'手持' – Kyle 2010-09-11 22:30:04
让我感到困惑的是,python没有一个可靠的实现来处理时区 – Kyle 2010-09-12 00:48:37