Convert python datetime to epoch with strftime

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 … Read more

Converting datetime.date to UTC timestamp in Python

I am dealing with dates in Python and I need to convert them to UTC timestamps to be used inside Javascript. The following code does not work: >>> d = datetime.date(2011,01,01) >>> datetime.datetime.utcfromtimestamp(time.mktime(d.timetuple())) datetime.datetime(2010, 12, 31, 23, 0) Converting the date object first to datetime also does not help. I tried the example at this … Read more