Using %f with strftime() in Python to get microseconds

前端 未结 8 1921
渐次进展
渐次进展 2020-11-29 21:32

I\'m trying to use strftime() to microsecond precision, which seems possible using %f (as stated here). However when I try the following code:

import time
im         


        
8条回答
  •  离开以前
    2020-11-29 21:51

    You can use datetime's strftime function to get this. The problem is that time's strftime accepts a timetuple that does not carry microsecond information.

    from datetime import datetime
    datetime.now().strftime("%H:%M:%S.%f")
    

    Should do the trick!

提交回复
热议问题