
比如采集的时间格式:2017-9-5 12:00:00,对于这种非标准的时间怎么处理成标准时间格式?
ftime='2017-9-5 12:00:00' date,time=ftime.split(' ') year,month,day=date.split('-') if len(month)==1: mOnth='0'+month if len(day)==1: day='0'+day ftime2='-'.join([year,month,day])+' '+time 
1 haddy Sep 5, 2017 >>> datetime.datetime.strptime("2017-9-5 12:30:45", "%Y-%m-%d %H:%M:%S") datetime.datetime(2017, 9, 5, 12, 30, 45) |
2 haddy Sep 5, 2017 python 文档里描述得不是特别清晰,实际上是可以用的 |
3 187j3x1 Sep 5, 2017 |
6 billgreen1 Sep 5, 2017 有的,使用 pandas 的 Timestamp import pandas as pd pd.Timestamp("2017-9-5 13:05") 你会的到你想要的 |
7 qiayue PRO 果然还是 PHP 最好 date('Y-m-d H:i:s', strtotime('2017-9-5 12:00:00')) |
8 jko123 OP @billgreen1 #6 一楼已经解决了。datetime 也可以处理 |
9 billgreen1 Sep 5, 2017 @chen2016 一楼的解决方案需要你指定格式,我给出的这个,你不需要指定格式的。哪怕你用 2017/9/5 它也能正确识别 |
10 Martin9 Sep 5, 2017 现在 v 站越来越多三楼这种人 block 了 |
11 jko123 OP @billgreen1 #9 啊!厉害了,谢谢 |
12 Les1ie Sep 5, 2017 ``` $ pip install arrow ``` 放弃 date 和 time 转到 arrow 吧... |
13 Les1ie Sep 5, 2017 突然发现 arrow.get()也拿不到这句话.. |