要获取具有毫秒(秒后3位小数)的日期字符串,请使用以下命令:
from datetime import datetime print datetime.utcnow().strftime(‘%Y-%m-%d %H:%M:%S.%f‘)[:-3]
输出2018-10-04 10:18:32.926
%f
显示毫秒
要在python中获得毫秒,请使用以下代码。
import datetime # 获得当前时间 now=datetime.datetime.now() #2019-04-11 14:18:41.629019 print(now) # 转换为指定的格式: otherStyleTime = now.strftime("%Y-%m-%d %H:%M:%S")#2019-04-11 14:18:41 print(otherStyleTime) #
输出如下所示
2019-03-11 17:34:28.290409
原文地址:https://www.cnblogs.com/xyao1/p/10689413.html
时间: 2024-07-31 06:53:40