import time, datetime
a = datetime.datetime.now()
print(str(a))
# '2018-08-19 21:01:42.811262'
detester = a.strftime(‘%Y-%m-%d')
b = time.localtime()
c = time.strftime("%Y-%m-%d", b)
print(c)
# '2018-08-19'
print(str(b))
#'time.struct_time(tm_year=2018, tm_mon=8, tm_mday=19, tm_hour=21, tm_min=2, tm_sec=20, tm_wday=6, tm_yday=231, #tm_isdst=0)'
注意:注意 time模块和datetime模块转换时间格式不同
指定某个格式 : %Y-%m-%d %H:%M:%S