Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get time zone information of the system in Python?

I want to get the default timezone (PST) of my system from Python. What's the best way to do that? I'd like to avoid forking another process.

like image 788
Josh Gibson Avatar asked Jul 10 '09 17:07

Josh Gibson


People also ask

Which Python library is used for timezone?

pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher. It also solves the issue of ambiguous times at the end of daylight saving time, which you can read more about in the Python Library Reference ( datetime. tzinfo ).


1 Answers

This should work:

import time time.tzname 

time.tzname returns a tuple of two strings: The first is the name of the local non-DST timezone, the second is the name of the local DST timezone.

Example return: ('MST', 'MDT')

like image 64
Johannes Weiss Avatar answered Nov 10 '22 11:11

Johannes Weiss