获取当前时间datetime
datetime.datetime.now()# datetime.datetime(2023, 3, 29, 20, 10, 19, 634442)
获取当前年月日
datetime.datetime.now().strftime('%Y%m%d')# '20230323'
获取当前秒
datetime.datetime.now().second# 21秒
获取当前年月日时分秒
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") # '2023-03-29 20:11:42'datetime.datetime.now().strftime('%F %T')# '2023-03-29 20:12:42'
获取当前时间年月日时分秒毫秒
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S %f")# '2023-03-29 20:16:35 374846'
time
import timeimport datetimet = time.time()print (t) #原始时间数据, 1684304569.8328009print (int(t)) #秒级时间戳, 1684304569print (int(round(t * 1000))) #毫秒级时间戳, 1684304569833print (int(round(t * 1000000))) #微秒级时间戳, 1684304569832801
来源地址:https://blog.csdn.net/weixin_40400335/article/details/129929224