Skip to content

Instantly share code, notes, and snippets.

@alanfranz
Created May 22, 2017 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanfranz/40aba4f62e439164a992fda1133ad556 to your computer and use it in GitHub Desktop.
Save alanfranz/40aba4f62e439164a992fda1133ad556 to your computer and use it in GitHub Desktop.
python timezone information error
#!/usr/bin/env python
import os
import time
# The following is a file in /usr/share/zoneinfo
os.environ["TZ"] = "Europe/Rome"
time.tzset()
import sys
print sys.version_info
import commands
print "System time: %s" % commands.getoutput("date --rfc-3339=seconds")
import logging
import datetime
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout,
format="%(asctime)s:" + logging.BASIC_FORMAT,
datefmt="%Y-%m-%dT%H:%M:%S%z")
logger = logging.getLogger()
logger.info("Something happened")
@alanfranz
Copy link
Author

Verified that /usr/share/zoneinfo/Europe/Rome exists.

Output on Ubuntu Xenial:

sys.version_info(major=2, minor=7, micro=12, releaselevel='final', serial=0)
System time: 2017-05-22 11:25:36+02:00
2017-05-22T11:25:36+0000:INFO:root:Something happened

Output on Ubuntu Trusty:

sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0)
System time: 2017-05-22 11:29:34+02:00
2017-05-22T11:29:34+0000:INFO:root:Something happened

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment