Blogger Information
Blog 75
fans 0
comment 0
visits 54632
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
小猿圈Python实现得到当前时间偏移day天后的日期方法
聆听的博客
Original
944 people have browsed it

对于Python相信很多小伙伴都不陌生吧,从语言排行榜十以外到现在的第三,可见python是现在很热门的一种语言,Python开发的人都在一直的增加,今天小猿圈Python就分享一个实现得到当前时间偏移day天后的日期方法,希望对你学习Python有所帮助。


如下所示:

实例

 import datetime
#以当前时间作为起始点,days=-7向前偏移7天,days=7向后偏移7天
time_now = datetime.datetime.now()
time = (time_now+datetime.timedelta(days=7)).strftime("%Y%m%d")
print(time)

安装dateutil库,注意不是pip install dateutil,而是pip install python-dateutil

实例

import datetime
from dateutil.relativedelta import relativedelta

实例

#以当前时间作为起始点,days=-7向前偏移7天,days=7向后偏移7天
time_now = datetime.datetime.now()
time = (time_now+datetime.timedelta(days=7)).strftime("%Y%m%d")
print(time)
#以当前时间为起始点,偏移一个月
time_1=(time_now+relativedelta(months=-1)).strftime("%Y%m%d")
print(time_1)

以上就是小猿圈Python老师给大家介绍的Python实现得到当前时间偏移day天后的日期方法,相信很多同学对于Python有了一定的了解,如果感觉小猿圈讲的还不错的话,可以分享给身边人,小猿圈为大家提供一个良好的学习平台,一定要好好珍惜学习。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!