Python之比较日期大小

from datetime import *
d1, m1, y1 = [int(x) for x in input("Enter first"
                                    " person's date(DD/MM/YYYY) : ").split('/')]
b1 = date(y1, m1, d1)

d2, m2, y2 = [int(x) for x in input("Enter second"
                                    " person's date(DD/MM/YYYY) : ").split('/')]
b2 = date(y2, m2, d2)

if b1 == b2:
    print("Both persons are of equal age")
elif b1 > b2:
    print("The second person is older")
else:
    print("The first person is older")
def diff_datetime(timestamp):
    now = datetime.datetime.now().strftime('%Y-%m-%d')
    y1, m1, d1 = [int(x) for x in now.split('-')]
    b1 = datetime.date(y1, m1, d1)
    c_time = datetime.datetime.utcfromtimestamp(timestamp).strftime("%Y-%m-%d")
    y2, m2, d2 = [int(x) for x in c_time.split('-')]
    b2 = datetime.date(y2, m2, d2)
    return b1 == b2
# 差8小时处理方式
c_time = datetime.datetime.utcfromtimestamp(timestamp+28800).strftime("%Y-%m-%d")

你可能感兴趣的:(python)