Reputation: 952
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")
print(t)
#do something else for a little
t = time.strftime("%b-%d-%y at %I:%m%p")
print(t)
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)
print(t)
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??
Upvotes: 2
Views: 299
Reputation: 3265
You are using %m
at %I:%m%p
to format your "minutes", which actually means a month in decimals. Try capital %M
instead to get the minutes.
So,
time.strftime("%b-%d-%y at %I:%M%p")
See strftime documentation for the format directives.
Upvotes: 3