python - 在python中以10秒的间隔打印当前时间10次
问题描述
这会打印当前时间,间隔 10 秒我必须使用什么函数或循环
import time;
localtime = time.asctime(time.localtime(time.time()))
print "Local current time :", localtime
解决方案
你应该更好地论证这个问题!
顺便说一句,如果你试图每 10 秒打印一次当前时间 10 次,你可以这样做:
import time
from datetime import datetime
#For 10 times
for x in range(10):
# Get current time
now = datetime.now()
# Make a string of it
current_time = now.strftime("%H:%M:%S")
# Print it
print(current_time)
# Wait for 10 seconds
time.sleep(10)
输出:
14:33:33
14:33:43
14:33:53
14:34:03
14:34:13
14:34:23
14:34:33
14:34:43
14:34:53
14:35:03
推荐阅读
- openedge - 如何将临时表从过程文件传递到窗口
- r - 在 R 中的 plotly 或 ggplot 中将箭头(或箭头图像)添加到条形图上?
- html - 在跨越一定行数的动态生成的 html 表中浮动图标或 div
- spring - 如何处理 Spring Batch 中的 blob 字段?
- python - 从magnetlink infohash获取元数据
- parsing - 为什么我的解析器生成报告该 LALR(1) 语法不是 LALR(1)?
- java - 在 Java 中哪里设置参数 min.insync.replicas 和 acks?
- typescript - 如何动态更改 VSCode 扩展上的文档文本
- angular - 角 | 使用定时器每 5 秒刷新一次表
- linux - 基本操作系统 - Hera 5.1 - 无法登录 - “会话返回错误代码 1” - 意外删除了 zeitgeist*