以下是一个示例代码,根据开始后的20分钟来设定常规。
import time
def set_routine():
# 获取当前时间
current_time = time.time()
# 计算20分钟后的时间戳
target_time = current_time + 20 * 60
# 将时间戳转换为可读的时间格式
target_time_struct = time.localtime(target_time)
target_time_str = time.strftime("%Y-%m-%d %H:%M:%S", target_time_struct)
# 设置常规的操作
print("按照开始后的20分钟来设定常规...")
print("当前时间:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print("设定的常规时间:", target_time_str)
# 在这里添加你需要设定的常规操作
# 调用函数设置常规
set_routine()
这段代码通过time
模块获取当前时间戳,并计算出20分钟后的时间戳。然后,使用time.strftime()
函数将时间戳转换为可读的时间格式。接下来,你可以在函数中添加你需要设定的常规操作。最后,通过调用set_routine()
函数,即可执行这些常规操作。
上一篇:按照开始和结束日期筛选表格