1.导入库
import datetime
import time
2.获取时间
import datetime
import time
now_time = datetime.datetime.now() # 时间带毫秒小数点
print(now_time)
now_time = datetime.datetime.now().replace(microsecond=0) # %Y-%m-%d %H:%M:%S
print(now_time)
now_time = time.time() # timestamp
print(now_time)
now_time = time.localtime() # time struct
print(now_time)
now_time = time.localtime().tm_hour # %H
print(now_time)
now_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # %Y-%m-%d %H:%M:%S
print(now_time)