Convert python datetime to epoch with strftime

前端 未结 8 2321
执念已碎
执念已碎 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 10:49

    import time
    from datetime import datetime
    now = datetime.now()
    
    # same as above except keeps microseconds
    time.mktime(now.timetuple()) + now.microsecond * 1e-6
    

    (Sorry, it wouldn't let me comment on existing answer)

提交回复
热议问题