Quantcast
Channel: Convert python datetime to epoch with strftime - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Convert python datetime to epoch with strftime

$
0
0

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 example.

>>>datetime.datetime(2012,04,01,0,0).strftime('%s')'1333234800'

1st of April 2012 UTC from epoch is 1333238400 but this above returns 1333234800 which is different by 1 hour.

So it looks like that strftime is taking my system time into account and applies a timezone shift somewhere. I thought datetime was purely naive?

How can I get around that? If possible avoiding to import other libraries unless standard. (I have portability concerns).


Viewing all articles
Browse latest Browse all 9

Latest Images

Trending Articles



Latest Images