python 的time和datetime常用写法
import time from datetime import datetime from datetime import timedelta #打印时间串 print(time.time())#1574387008.6881413 #打印当时时间 print (time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))#2019-11-22 09:43:28 print (datetime.now().strftime("%Y-%m-%d %H:%M:%S"))#2019-11-22 09:43:28 #时间差的写法 now=datetime.now() yesterday=now+timedelta(days=-1) print(now) #2019-11-22 09:43:28.688141 print(yesterday) #2019-11-21 09:43:28.688141 print(yesterday.strftime("%Y-%m-%d %H:%M:%S")) #2019-11-21 09:43:28