Search code examples
pythontimezonedstpytzdjango-timezone

pytz alternative - using OS timezone as source?


Are there any simpler pytz alternative using OS timezone/dst as as source?

a ctypes wrapper or something doesn't require compiling would be welcome.

Edit: the beast


Solution

  • tzlocal module finds pytz timezone that corresponds to your OS local timezone on *nix and Win32:

    from datetime import datetime
    from tzlocal import get_localzone # $ pip install tzlocal
    
    print(datetime.now(get_localzone()))
    # -> 2015-01-27 07:20:52.163408+01:00
    

    Your distribution may patch pytz module to use OS tz database instead of embed one (e.g., Ubuntu does it).