datetime 计算时间差
计算时间差:
.date() # 格式化
.timedelta() # 时间差
import datetime # 今天 today = datetime.datetime.now() print(today) # 2019-03-11 16:24:23.792301 today = datetime.datetime.now().date() print(today) # 2019-03-11 # 昨天 yesterday = datetime.datetime.now().date() - datetime.timedelta(days=1) print(yesterday) # 2019-03-10 # 一周前 weekdelta = datetime.datetime.now().date() - datetime.timedelta(weeks=1) print(weekdelta) # 2019-03-04 # 一个月前 monthago = datetime.datetime.now().date() - datetime.timedelta(weeks=4) print(monthago) # 2019-02-11
参考博客:
https://www.cnblogs.com/amber-liu/p/10120503.html
- time模块官方文档
- datetime模块官方文档
- 廖雪峰的官方网站
- http://blog.csdn.net/you_are_my_dream/article/details/61616465
- http://blog.csdn.net/tigerking1017/article/details/51332220
- http://blog.csdn.net/cherdw/article/details/55224209
- https://www.cnblogs.com/cindy-cindy/p/6720196.html
- https://blog.csdn.net/python3_2017/article/details/78983370
- https://blog.csdn.net/qq_25420115/article/details/53149669