Python: Figure out local timezone

前端 未结 18 1694
野性不改
野性不改 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 15:58

    now_dt = datetime.datetime.now()
    utc_now = datetime.datetime.utcnow()
    now_ts, utc_ts = map(time.mktime, map(datetime.datetime.timetuple, (now_dt, utc_now)))
    offset = int((now_ts - utc_ts) / 3600)
    

    hope this will help you.

提交回复
热议问题