Convert python datetime to epoch with strftime

前端 未结 8 2419
执念已碎
执念已碎 2020-11-22 10:15

I have a time in UTC from which I want the number of seconds since epoch.

I am using strftime to convert it to the number of seconds. Taking 1st April 2012 as an exa

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 11:03

    For an explicit timezone-independent solution, use the pytz library.

    import datetime
    import pytz
    
    pytz.utc.localize(datetime.datetime(2012,4,1,0,0), is_dst=False).timestamp()
    

    Output (float): 1333238400.0

提交回复
热议问题