Convert python datetime to epoch with strftime

前端 未结 8 2313
执念已碎
执念已碎 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:59

    I had serious issues with Timezones and such. The way Python handles all that happen to be pretty confusing (to me). Things seem to be working fine using the calendar module (see links 1, 2, 3 and 4).

    >>> import datetime
    >>> import calendar
    >>> aprilFirst=datetime.datetime(2012, 04, 01, 0, 0)
    >>> calendar.timegm(aprilFirst.timetuple())
    1333238400
    

提交回复
热议问题