python的日志记录模块报告cygwin下的时区不正确 [英] logging module for python reports incorrect timezone under cygwin

查看:153
本文介绍了python的日志记录模块报告cygwin下的时区不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Windows 7上cygwin下使用日志记录模块的python脚本.date命令报告正确的时间:

I am running python script that uses logging module under cygwin on Windows 7. The date command reports correct time:

$ date
Tue, Aug 14, 2012  2:47:49 PM

但是,python脚本有五个小时的休假时间:

However, the python script is five hours off:

2012-08-14 19:39:06,438: Done!

为脚本配置日志记录时,我没有做任何花哨的事情:

I don't do anything fancy when I configure logging for the script:

logging.basicConfig(format='%(asctime)-15s: %(message)s', level=logging.DEBUG)

有人可以告诉我怎么回事以及如何解决吗?

Can someone tell me what is going on and how I can fix it?

推荐答案

在导入日期/时间模块之前,您需要在python脚本中取消设置环境"TZ".它由cygwin设置,但Windows无法理解:

You need to unset the environment "TZ" in your python script prior to any importing the date/time modules. It is set by cygwin but not understood by Windows:

if os.getenv("TZ"):
    os.unsetenv("TZ")

这篇关于python的日志记录模块报告cygwin下的时区不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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