John Machin <[EMAIL PROTECTED]> wrote: >On 11/08/2006 11:35 PM, John Machin wrote: >> On 11/08/2006 11:10 PM, Simen Haugen wrote: >>> How can I convert a python datetime to a timestamp? It's easy to convert >>> a timestamp to datetime (datetime.datetime.fromtimestamp(), but the >>> other way around...?) >> Is the timetuple() method what you want? > [ ... ] >Aaaarrrggghhh no it's not what you want -- [ ... ]
It is if you only want it to the second. It just needs a time.mktime(): >>> n = time.time() >>> n 1155307613.4550381 >>> d = datetime.datetime.fromtimestamp(n) >>> time.mktime(d.timetuple()) 1155307613.0 (timetuple() is responsible for the loss of the fractional part.) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- http://mail.python.org/mailman/listinfo/python-list