Sunday 15 July 2012

python - Another converting hh:mm:ss to seconds -


I have seen some questions that do not want to leave my status and want the same format, time format is not always: mm: ss Sometimes it's just mm: ss

I understand the idea here and here

What I do not understand is that HH: mm: SS, H Def: Get sec (s): l = s.split (':') Return int (L [0]) * 3600 + s (s): mm: ss, mm: ss or bus m: ss

 Int (L [1]) * 60 + Int (L [2])   

Edit: I think my Wal is not enough I'm searching for a solution to handle all possible formats with 1 single function.

  def GetSec (s): l = map (int, s.split (': ')) # L = List (map (int, s.split (': ')) Python 3.x return amount (in n * sec) for node, second in zip (L [:: - 1], (1, 60, 3600)) getSec ('20 ') # 20 getSec (' 1:20 ') # 80 getSec (' 1:30:01 ') # 5401    

No comments:

Post a Comment