目的: 用于云函数中每日自动获取姨妈日期 代码:
from datetime import datetime, date
import datetime as pt
# 计算大姨妈(姨妈日期,今日日期,周期,每月推迟天数
def get_mum(momday1, today, round, tempday):
try:
ym = 6
mm_year = int(momday1.split("-")[0])
mm_month = int(momday1.split("-")[1])
mm_day = int(momday1.split("-")[2])
momday = date(mm_year, mm_month, mm_day)
sumdays = str(today.__sub__(momday)).split(" ")[0]
days = int(int(sumdays) / round)
TempDay = tempday * days
delta = pt.timedelta(days=days * round + TempDay)
startday = momday + delta
delta = pt.timedelta(days=ym - 1)
lastday = startday + delta
if startday <= today <= lastday:
if today != lastday:
time1 = str(today.__sub__(startday))[0]
mytext = '今天是来姨妈的第' + str(int(time1) + 1) + '天,还要坚持' + \
str(lastday.__sub__(today)).split(" ")[0] + '天哦'
else:
mytext = '今天是来姨妈的最后一天,明天就可以愉快地玩耍啦'
else:
a = int(str(lastday.__sub__(today)).split(" ")[0]) + 1
if a <= 0:
dy = 32 - ym - abs(a)
else:
dy = a - ym
mytext = '大姨妈还有' + str(dy) + '天到达战场'
except:
mytext = ''
return mytext
for i in range(0, 100):
delta = pt.timedelta(days=i)
today = datetime.date(datetime(year=2022, month=9, day=20))
lastday = today + delta
motertext = get_mum('2022-07-21', lastday, 31, 1)
print('今日:' + str(lastday) + '\t\t' + motertext)
今天的文章python的计算器代码_用python做一个简易计算器[通俗易懂]分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/67048.html