简体   繁体   English

转换为本地时区会在不同机器上产生不同的值

[英]Conversion to local time zone yields different value in different machine

I am storing few tweets in mongodb in UTC format and converting utc time specified in tweets to local time zone in my local machine it renders correctly in local machine but not in my server. 我以UTC格式在mongodb中存储了几条推文,并将推文中指定的utc时间转换为我的本地计算机中的本地时区,它在本地计算机中正确呈现,但在我的服务器中未正确显示。

Storing 储存

        #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})

Conversion 转换次数

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

Output 输出量

Thu Apr 19 04:00:00 2012
Thu Apr 19 03:00:00 2012

Output in Local Machine 在本地机器上输出

Thu Apr 19 09:00:00 2012 
Thu Apr 19 08:00:00 2012 

Local machine time zone is set to 'IST', server time zone is set to 'UTC'. 本地计算机时区设置为“ IST”,服务器时区设置为“ UTC”。

here = tz.gettz('Asia/Colombo')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM