python time 时间处理

时间:2023-03-09 06:46:15
python time 时间处理

a='2018-03-26 17:20:11'

>>> print time.strftime("%Y%m%d", a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument must be 9-item sequence, not str
>>> time.localtime()
time.struct_time(tm_year=2018, tm_mon=5, tm_mday=17, tm_hour=20, tm_min=26, tm_sec=41, tm_wday=3, tm_yday=137, tm_isdst=0)

>>> b=time.strptime(a,"%Y-%m-%d %H:%M:%S")
>>> print time.strftime("%Y%m%d", b)
20180326