Skip to content

Instantly share code, notes, and snippets.

@TakamiChie
Created January 12, 2023 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakamiChie/a52eeb7d0379b53d360f3bc6825788d0 to your computer and use it in GitHub Desktop.
Save TakamiChie/a52eeb7d0379b53d360f3bc6825788d0 to your computer and use it in GitHub Desktop.
mm:ss~mm:ss を 何秒目から何秒間 表記に変換する
t = """
12:05~12:59
13:01~13:25
14:32~15:22
"""
times = t.strip().split("\n")
for time in times:
s = list(map(lambda x: x.split(":"), time.split("~")))
start = int(s[0][0]) * 60 + int(s[0][1])
length = int(s[1][0]) * 60 + int(s[1][1]) - start
time = f"{start}:{length}"
print(time) # time,time,time などという形式にしたいときには、第二引数としてend=","とする
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment