Skip to content

Instantly share code, notes, and snippets.

@TakamiChie
Created November 27, 2018 15:48
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/e245185d35af17b40e040c2bd2376467 to your computer and use it in GitHub Desktop.
Save TakamiChie/e245185d35af17b40e040c2bd2376467 to your computer and use it in GitHub Desktop.
文章中の時間表記をシフトするPythonコードのひな形
# あとで再利用可能な形にまとめるかも
# ex). 23:00→30分前を指定 22:30
import re
import math
s = """
ここに変換したい文章を入れる
"""
def timeshift(m):
t = int(m.group(1)) * 60 + int(m.group(2))
t -= 0 # ここでタイムシフトしたい時間(分)を指定する
return "{0:02d}:{1:02d}".format(math.floor(t // 60), int(t % 60))
print(re.sub(r'(\d{1,2}):(\d{1,2})', timeshift, s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment