简体   繁体   English

在Python中,如何在给定的日期设置提醒?

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

相关问题 考虑到附近的山脉(使用 Python),如何计算给定日期和位置的日照时数? - How can I calculate the number of sun hours for a given day and location, considering nearby mountains (with Python)? Python:我怎样才能看出今年某个月和今天是否已经过去了? - Python: How can I see if a given month and day have already passed this year? 如何在用户给定的Python中添加无限的整数集? - How can I add an unlimited set of integers in Python given by the user? 给定日期对象在python中,我怎么减去一天 - given a date object in python, how do I subtract one day 如何在 django/python 中的 2 小时前向客户发送提醒消息 - How can i send reminder message to customer before 2 hours in django/python 如果给定的日期是本月的最后一天,如何增加月份数? - How can I increment month number if given day is last day of current month? 给定日期列表,我如何将它们组合/格式化为字符串,例如“Day1-Day3,Day5 Month Year” - Given a list of dates, how can I combine/format them as a string like "Day1-Day3, Day5 Month Year" 如何在python中迭代给定一天的几个小时? - How to iterate over hours of a given day in python? 如何在 python 中将 1 天添加到给定日期 - how to add 1 day to given date in python 如何在 discord.py 中创建提醒命令? - How can i create a reminder command in discord.py?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM