[英]In Python, how can I set a reminder on a given day?
我正在制作一个用于启动其他程序的Python程序,但我想添加一个功能,例如,如果该程序在周三使用,它可能会说'拿起孩子'或者类似的提醒
You can use the built-in time
module to get the current day of the week. 您可以使用内置
time
模块来获取当周的当天。
>>> import time
>>> time.localtime().tm_wday
5
The 5 indicates that it is Saturday here. 5表示这是星期六。
See datetime.date for working with dates where the time and timezone do not matter. 请参阅datetime.date以了解时间和时区无关紧要的日期。
For readability, I would use: 为了便于阅读,我会使用:
import datetime
if datetime.date.today().strftime('%A') == 'Wednesday':
print("Pick up the kids!")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.