import datetime
#打印当天的时间
#datetime.datetime.now()
today=datetime.datetime.now()
print(today)
#打印N天后的时间
#datetime.timedelta(days=天数)
n=26
delta=datetime.timedelta(days=n) #将N天处理为可运算的时间类型
afday=today+delta
print(afday)
#将字符串转换为日期
# datetime.datetime.strptime(时间字符串,时间格式)
strday="2017-10-07"
dtday=datetime.datetime.strptime(strday,'%Y-%m-%d')
print(type(dtday))
#将日期转为字符串
#strftime(时间格式)
dpsday=today.strftime('%Y-%m-%d')
print(dpsday)
#计算两个时间的间隔
distance=afday-today
print(distance)
#将时间间隔转化为整型
#days
intdis=distance.days
print(intdis,type(intdis))
#日子判断,如果是12号,则输出还款
today=datetime.datetime.now().day
print(today,type(today))
if today==12:
print("今天是还款日")
|
|