我要求将日期从本地时间戳转换为UTC然后再转换回本地时间戳.
奇怪的是,当从UTC转换回本地时,python决定它是PDT而不是原始的PST,所以转换后的日期已经增加了一个小时.有人可以向我解释发生了什么或我做错了什么?
from datetime import datetime
from pytz import timezone
import pytz
DATE_FORMAT = '%Y-%m-%d %H:%M:%S %Z%z'
def print_formatted(dt):
formatted_date = dt.strftime(DATE_FORMAT)
print "%s :: %s" % (dt.tzinfo, formatted_date)
#convert the strings to date/time
date = datetime.now()
print_formatted(date)
#get the user's timezone from the pofile table
users_timezone = timezone("US/Pacific")
#set the parsed date's timezone
date = date.replace(tzinfo=users_timezone)
date = date.astimezone(users_timezone)
print_formatted(date)
#Create a UTC timezone
utc_timezone = timezone('UTC')
date = date.astimezone(utc_timezone)
print_formatted(date)
#Convert it back to the user's local timezone …Run Code Online (Sandbox Code Playgroud) 我一直在我的webfaction帐户上安装django社交注册.到目前为止我有facebook登录工作.当我尝试登录到Twitter时,我得到了正确的登录页面,但在选择"允许"后,我转发到以下URL:
http://example.com/social/twitter/callback/ ....其中"example.com"是转发到的实际网址.
我已经设置了twitter应用程序并输入了有效的oauth回调URL.
我在我的开发者机器上搜索了代码以获取对"example.com"的引用,但是没有找到任何代码.
任何有助于确保这一点的人都将不胜感激.