Fork me on GitHub

版权声明 本站原创文章 由 萌叔 发表
转载请注明 萌叔 | https://vearne.cc

在不考虑闰年,润日的情况下计算某人的下一次生日

from datetime import datetime, timedelta


def solve(birthday):
    now = datetime.now()
    now = datetime(now.year, now.month, now.day)
    year = (now.year - birthday.year) + birthday.year
    x = datetime(year, birthday.month, birthday.day)
    if x < now:
        x = datetime(x.year + 1 , x.month, x.day )
        return x
    else:
        return x


b1 = datetime(1985, 11, 1)
print solve(b1)
b2 = datetime(1982, 3, 15)
print solve(b2)
b3 = datetime(1985, 7, 15)
print solve(b3)
~

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注