Chad K Chad K - 1 month ago 4x
Python Question

time.strftime() not updaing

I am trying to get the time when a button is pushed, but I am going to have a few pushes without starting and calling the time module. In Ipython, I tested out some code, and the time is not updating

import time
t = time.strftime("%b-%d-%y at %I:%m%p")
#do something else for a little
t = time.strftime("%b-%d-%y at %I:%m%p")

It gives me the same time

even if I put in a time tuple such as:

lt = time.localtime(time.time())
t = time.strftime("%b-%d-%y at %I:%m%p", lt)

I get the same time

Even if I wait, and execute the code again (in Ipython), it gives me the same time.

time.time() will give me a new time every time though

I don't know if doing it in Ipython (I'm just testing code before I put it in my python file) matters

What am I doing wrong??


You are using %m at %I:%m%p to format your "minutes", which actually means a month in decimals. Try capital %Minstead to get the minutes.


time.strftime("%b-%d-%y at %I:%M%p")

See strftime documentation for the format directives.