I have a datetime.time
object (no date part) in python, and want to find out how many seconds has elapsed since midnight. t.hour * 3600 + t.minute * 60 + t.second
will surely work, but is there a more pythonic way?
相关问题
- 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
Unfortunately, it seems you can't get a
timedelta
object from twodatetime.time
objects. However, you can build one and use it withtotal_seconds()
to get the number of seconds since midnight:You could use
datetime.combine()
to create adatetime
object, to gettimedelta
:It supports microseconds and any other future
datetime.time.resolution
.