我在UTC格式的mongodb中存储了一些推文,并将推文中指定的utc时间转换为本地计算机中的本地时区,它在本地计算机中正确呈现,但不在我的服务器中呈现。
#d is the tweet
created_at = d['created_at']
dt = datetime.datetime.strptime(created_at,\
"%a %b %d %H:%M:%S +0000 %Y")
dt = dt.replace(second = 0, minute=0)
db.collection({'created_at': dt})
here = tz.tzlocal('Asia/Colombo')
utc = tz.gettz('UTC')
for index, item in enumerate(items):
ist = item['created_at'].replace(tzinfo=utc).astimezone(here)
ist_readable = ist.replace(minute =0, second = 0).ctime()
items[index]['created_at'] = ist_readable
return items
Thu Apr 19 04:00:00 2012
Thu Apr 19 03:00:00 2012
Thu Apr 19 09:00:00 2012
Thu Apr 19 08:00:00 2012
本地计算机时区设置为“IST”,服务器时区设置为“UTC”。
答案 0 :(得分:0)
here = tz.gettz('Asia/Colombo')