In Python, how do I convert a datetime.datetime
into the kind of float
that I would get from the time.time
function?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
It's not hard to use the time tuple method and still retain the microseconds:
Should do the trick.
Given a
datetime.datetime
objectdt
, you could useExample:
Note that the
timedelta.total_seconds()
method was introduced in Python 2.7.I know this is an old question, but in python 3.3+ there is now an easier way to do this using the datetime.timestamp() method:
A combination of
datetime.timetuple()
andtime.mktime()
: