要在python中,要獲取具有毫秒(秒后3位小數)的日期字符串,請使用以下命令:
%f
顯示毫秒
import datetime # 獲得當前時間 now=datetime.datetime.now() #2019-04-11 14:18:41.629019 print(now) # 具有毫秒(秒后3位小數)的日期 # 轉換成str后切片 print(str(now)[:-3])
import time
curtime=time.strftime("%Y-%m-%d %H:%M.%S")
print(curtime)#2019-05-16 15:56.51
#
輸出如下所示
2019-03-11 17:34:28.290409