python 正则匹配时间格式转换方法

import re
from datetime import datetime
a = '2018年8月9日 10:10'
s = re.findall('\d+',a)
print(s)
d = ' '.join(s)
print(d)
f = datetime.strptime(d,'%Y %m %d %H %M').strftime('%Y/%m/%d %H:%M')
print(f)
》》》》》》《结果》

['2018', '8', '9', '10', '10']
2018 8 9 10 10
2018/08/09 10:10

《《《《《



 

posted @ 2018-10-24 18:52  三冬三夏  阅读(1209)  评论(0编辑  收藏  举报