[英]How to check if it's a certain time like e.g. 2:00pm
I'm making an automation with selenium and PyAutoGui that sends an email to my friends at exactly 2:00pm, but I don't understand what format the我正在使用 selenium 和 PyAutoGui 进行自动化,在下午 2:00 向我的朋友发送电子邮件,但我不明白是什么格式
datetime.datetime.now()
日期时间.日期时间.现在()
returns in, and how to figure out when its 2:00pm(what I mean by format is what this returns in) can someone help me?返回,以及如何确定其下午 2:00 的时间(我的意思是格式是返回的内容)有人可以帮助我吗?
Not quite sure what you mean, but you can convert datetime to a string and check if it's 2pm like this:不太确定你的意思,但你可以将日期时间转换为字符串并检查它是否是下午 2 点,如下所示:
import datetime
time = datetime.datetime.now().strftime('%H:%M:%S')
if time == '14:00:00':
print("It's 2pm")
else:
print(f"It's {time}, that's not 2pm")
Is this what you're looking for?这是你要找的吗?
dates are converted to iso 8601 strings日期转换为 iso 8601 字符串
import datetime
#https://strftime.org/
d=datetime.datetime.now()
print(d.strftime("%Y/%m/%d"))
print(d.strftime("%H:%m %p"))
match=d.strftime("%H:%m %p")=="14:00 PM"
print(match)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.