1
omg21 OP 还有,‘ 16/06/10 ’如何转换成‘ 2016-06-10 ’?
|
2
Livid MOD PRO |
3
terence4444 2016 年 6 月 17 日 via iPhone
你漏了使用 strftime 那一步
|
4
oclock 2016 年 6 月 17 日
arrow +1
|
5
rapospectre 2016 年 6 月 17 日
既然都是字符串为啥不直接 str.replace('/', '-')
|
6
mulog 2016 年 6 月 17 日
人生苦短 早用 arrow 早享受。。
|
7
wowo2088 2016 年 6 月 17 日
str.replace('/', '-') +1
|
8
hellorocky728 2016 年 6 月 17 日
|
9
aitaii 2016 年 6 月 17 日
字符串 直接替换就好了
|
10
wmttom 2016 年 6 月 17 日
自从用了 arrow ,就可以手写一切时间转化了
|
11
practicer 2016 年 6 月 17 日 t = datetime.datetime.strptime(str, '%Y/%M/%d').strftime('%Y-%M-%d')
datetime.datetime.strptime() 解析时间类字符串,返回 datetime 对象 datetime.datetime.strftime()相反,将 datetime 对象转成实践类的字符串 |
13
practicer 2016 年 6 月 18 日
re.sub(u'^(\d+) 年 (\d+) 月 (\d+) 日$', r'\1-\2-\3', str)
这种情况最好用 re 模块的替换函数了 r'\1-\2-\3'里面\1 \2 \3 分别表示 group(1), group(2), group(3),记得不能省略 r ,也不能省略前面 regex 语句的 u |