Python Time conversion h:m:s to seconds

后端 未结 7 1239
青春惊慌失措
青春惊慌失措 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 11:51

    This works in 2.6.4:

    hours, minutes, seconds = [int(_) for _ in thestring.split(':')]
    

    If you want to turn it back into a timedelta:

    thetimedelta = datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds)
    

提交回复
热议问题