简体   繁体   English

如何检查是否是某个时间,例如下午 2:00

[英]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.

相关问题 Python下午5:00之后 - Python After 5:00pm 使用 Python (pandas, datetime) 在 dataframe 中查找事件(具有开始和结束时间)是否超过特定时间(例如下午 6 点) - Find whether an event (with a start & end time) goes beyond a certain time (e.g. 6pm) in dataframe using Python (pandas, datetime) 如何将7:00 pm转换为Python Datetime对象 - How To Covert 7:00pm to Python Datetime object 如何检查从flask传入到html文件的变量是否是某种类型(例如字符串、整数) - How to check whether a variable passed in from flask to an html file is a certain type (e.g. string, integer) 如何从时间序列图中排除某些日期(例如,周末)? - How can I exclude certain dates (e.g., weekends) from time series plots? 如何在整小时内激活 python 程序? (下午 12:00:00,上午 04:00:00) - How do I activate a python program at exact whole hours? (12:00:00pm, 04:00:00am) 如何检查Iterable中是否有任何奇数/偶数(例如列表/元组)? - How to check if there's any odd/even numbers in an Iterable (e.g. list/tuple)? 如何在 python 中将时间列值从 mm:ss 格式化为 hh:mm:ss? 例如,21:34 到 00:21:34 - How can I format time columns value from mm:ss to hh:mm:ss in python? e.g., 21:34 to 00:21:34 (Python)如何将具有日期和时间的列(例如UTC 2019-07-02 00:12:32)拆分为两个单独的列? - (Python) How can I split a column with both date and time (e.g. 2019-07-02 00:12:32 UTC) into two separate columns? 如何将日期时间列标题(例如 2007-03-01 00:00:00)转换为日期-月-年格式,即 2007-03-01 - How to Convert Datetime column header (e.g. 2007-03-01 00:00:00) into Date-Month-Year format i.e. 2007-03-01
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM