Python Time conversion h:m:s to seconds

后端 未结 7 1102
青春惊慌失措
青春惊慌失措 2021-01-02 11:32

I am aware that with the timedelta function you can convert seconds to h:m:s using something like:

>> import datetime
>> str(datetime.timedelta(s         


        
相关标签:
7条回答
  • 2021-01-02 12:04

    I'm not even sure I'd bother with timedelta for this

    >>> pseconds = lambda hms:sum(map(lambda a,b: int(a)*b,hms.split(':'),(3600,60,1)))
    >>> pseconds('0:11:06')
    666
    
    0 讨论(0)
提交回复
热议问题