Python datetime.now()为我提供了当前时间,包括毫秒,如下所示:
2014-08-22 19:23:40.630000
如何将上面的datetime对象转换为包含毫秒的字符串?
我调查了time.strftime()
一下,但没有提供毫秒级的选择。
有想法吗?
谢谢。
使用datetime.strftime。在Python 3.4.1中:
from datetime import datetime
mytime= datetime.now()
s= mytime.strftime("%Y-%b-%d %H:%M:%S.%f")
print(s)
'2014-Aug-23 08:51:32.911271'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句