AnsweredAssumed Answered

Milliseconds with strftime

Question asked by jborgion Champion on Aug 22, 2018
Latest reply on Aug 22, 2018 by jborgion

I need to return time to the millisecond;Python strftime reference  provides the %f format place holder, but when I use it in Python 3.x it fails.

 

This works:

from time import strftime
site = 'FP 20180822'
for i in range(1,10):
    theTime = strftime("%H%M%S")
    newTime = '{} {}'.format(site,theTime)
    print('{}'.format(newTime))

#and returns:
FP 20180822 162325
FP 20180822 162325
FP 20180822 162325
FP 20180822 162325
FP 20180822 162325
FP 20180822 162325
FP 20180822 162325
FP 20180822 162325
FP 20180822 162325


#the following fails with Invalid format String.
#Note the %f which allegedly provides milliseonds


from time import strftime
site = 'FP 20180822'
for i in range(1,10):
    theTime = strftime("%H%M%S%f") #### %f
    newTime = '{} {}'.format(site,theTime)
    print('{}'.format(newTime))

I was hoping that spinning it through a loop would get me down to the millisecond.  Any thoughts? (I can appended i at the end of new Time as a phony millisecond...)

Outcomes