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

前端 未结 8 1945
渐次进展
渐次进展 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:59

    When the "%f" for micro seconds isn't working, please use the following method:

    import datetime
    
    def getTimeStamp():
        dt = datetime.datetime.now()
        return dt.strftime("%Y%j%H%M%S") + str(dt.microsecond)
    

提交回复
热议问题