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

本文介绍了使用Python的time模块和datetime模块进行时间日期格式化的多种方法,并对比了两者的不同之处。
362

被折叠的 条评论
为什么被折叠?



