[Tutor] Hey.need help on time

eryksun eryksun at gmail.com
Thu Sep 6 11:08:18 CEST 2012

On Thu, Sep 6, 2012 at 4:25 AM, Ray Jones <crawlzone at gmail.com> wrote:
> Why the additional step of calling time.tzset()? Once os.environ['TZ']
> is set, I've found that time.localtime() responds to the new TZ without
> anything extra. Is that a difference in versions (2.7.3 here)?

It shouldn't strictly be necessary using glibc. I checked the source.
glibc localtime calls __tz_convert() on each call, which calls
tzset_internal() to update the TZ setting. However, I don't think
that's guaranteed in all C runtimes. As the Python docs say,
"[c]hanging the TZ environment variable without calling tzset *may*
change the local timezone used by methods such as localtime, but this
behaviour should not be relied on."

More information about the Tutor mailing list