python计算纪念日相关

注意需要python3

1、距离某一特定日期多少天后,如 100天

from datetime import datetime,timedelta
pre=datetime(2016,12,12,22,30,50,55) # 年月日时分秒 微秒
dst=pre+timedelta(days=100)#timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])
print(dst)

 2、现在距离某一天多久了

from datetime import datetime,timedelta
pre=datetime(2016,12,12,22,30,50,55) # 年月日时分秒 微秒
now=datetime.now()
dst=now-pre
print(dst)

 3、两个时间差

from datetime import datetime,timedelta
pre=datetime(2016,12,12,22,30,50,55) # 年月日时分秒 微秒
pre2=datetime(2016,12,13,22,30,50,55) # 年月日时分秒 微秒
dst=pre2-pre
print(dst)

 

posted @ 2017-12-24 00:15  愤怒的企鹅  阅读(949)  评论(0编辑  收藏  举报