Last active
December 28, 2015 20:19
-
-
Save hmkz/7557059 to your computer and use it in GitHub Desktop.
年月日,時分秒など日本語で書かれた日付をyyyy-MM-DD HH:mm:ssに変換する。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- encoding: utf8 -*- | |
import re | |
date_jpn = "2013年11月7日 08時43分52秒" | |
r = re.compile("(.*)年(.*)月(.*)日 (.*)時(.*)分(.*)秒") | |
# 抽出した値はタプルになっているので、タプルを配列に変換 | |
dt = list(r.search(date_jpn).groups()) | |
# 各値が10以下の場合、頭に「0」を付与する。 | |
dt = map((lambda val: "%02d" % int(val) if int(val) < 10 else val), dt) | |
print(" ".join(["-".join(dt[0:3]), ":".join(dt[3:6])])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment