要获取具有毫秒(秒后3位小数)的日期字符串,请使用以下命令:

from datetime import datetime

print datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

输出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 
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄