Python: Figure out local timezone

前端 未结 18 1717
野性不改
野性不改 2020-12-07 15:50

I want to compare UTC timestamps from a log file with local timestamps. When creating the local datetime object, I use something like:

>>&         


        
18条回答
  •  余生分开走
    2020-12-07 16:11

    First get pytz and tzlocal modules

    pip install pytz tzlocal
    

    then

    from tzlocal import get_localzone
    local = get_localzone()
    

    then you can do things like

    from datetime import datetime
    print(datetime.now(local))
    

提交回复
热议问题