【发布时间】:2026-02-02 00:10:01
【问题描述】:
使用 pytz 获取时间。当时间等于变量(字符串时间)时,我希望打印文本(最终播放声音)。时间在迭代,但是当有匹配时我无法打印语句。
#imports
import time
from datetime import datetime
import pytz
#current time
def clocktime():
while True:
tz_syd = pytz.timezone("Australia/Sydney")
Sydney_Time = datetime.now(tz_syd).strftime("%H:%M:%S")
time.sleep(1)
#iterator to check for time match
def alarmsystem(clocktime):
TestCaseA = "20:52:16"
TestCaseB = "20:53:29"
while True:
if clocktime == TestCaseB:
print("Time B Triggered")
elif clocktime == TestCaseA:
print("Time A Triggered")
print(alarmsystem(clocktime()))
非常感谢任何帮助!
【问题讨论】: