[英]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
在Ipython中,我测试了一些代码,并且时间没有更新
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. 即使我等待,然后再次执行代码(在Ipython中),它也给了我相同的时间。
time.time() will give me a new time every time though 不过time.time()每次都会给我一个新的时间
I don't know if doing it in Ipython (I'm just testing code before I put it in my python file) matters 我不知道在Ipython中这样做(我只是在将代码放入python文件中之前对其进行测试)很重要
What am I doing wrong?? 我究竟做错了什么??
You are using %m
at %I:%m%p
to format your "minutes", which actually means a month in decimals. 您正在
%I:%m%p
处使用%m
来设置“分钟”的格式,这实际上表示以小数表示的一个月 。 Try capital %M
instead to get the minutes. 尝试使用大写
%M
来获取分钟。
So, 所以,
time.strftime("%b-%d-%y at %I:%M%p")
See strftime documentation for the format directives. 有关格式指令,请参见strftime文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.