import datetime
nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')#现在
pastTimeMinutes = (datetime.datetime.now()+datetime.timedelta(minutes=5)).strftime('%Y-%m-%d %H:%M:%S')#5分钟后
pastTime = (datetime.datetime.now()-datetime.timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')#一小时前
afterTomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S')#后天
yesterday = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#昨天
tomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#明天
# print('\n',nowTime,'\n',pastTimeMinutes,'\n',pastTime,'\n',afterTomorrowTime,'\n',tomorrowTime)
print("现在: "+nowTime)
print("5分钟后: "+pastTimeMinutes)
print("一小时前: "+pastTime)
print("后天: "+afterTomorrowTime)
print("昨天: "+yesterday)
print("明天: "+tomorrowTime)
import datetime
nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')#现在
pastTimeMinutes = (datetime.datetime.now()+datetime.timedelta(minutes=5)).strftime('%Y-%m-%d %H:%M:%S')#5分钟后
pastTime = (datetime.datetime.now()-datetime.timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')#一小时前
afterTomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S')#后天
yesterday = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#昨天
tomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#明天
# print('\n',nowTime,'\n',pastTimeMinutes,'\n',pastTime,'\n',afterTomorrowTime,'\n',tomorrowTime)
print("现在: "+nowTime)
print("5分钟后: "+pastTimeMinutes)
print("一小时前: "+pastTime)
print("后天: "+afterTomorrowTime)
print("昨天: "+yesterday)
print("明天: "+tomorrowTime)

总结:

+datetime.timedelta(minutes=5)     加5分钟也就是5分钟之后的时间
-datetime.timedelta(days=1)        减1天时间也就是1天前的时间  
												

最新文章

  1. angular $http请求
  2. AOP programming paradiag
  3. LVM逻辑卷的创建及使用
  4. 李洪强漫谈iOS开发[C语言-046]-统计输入字符个数
  5. python高效解析日志入库
  6. 洛谷P1202 [USACO1.1]黑色星期五Friday the Thirteenth
  7. iOS开发——实战OC篇&环境搭建之纯代码(玩转UINavigationController与UITabBarController)
  8. 1218. Episode N-th: The Jedi Tournament(bfs)
  9. eCos中断模型
  10. AjaxPro使用说明
  11. Hadoop流程---从tpch到hive
  12. Linux下编译安装Apache及模块
  13. javascript方法的方法名慎用close
  14. call是什么?一次说个明白
  15. Docker----起步
  16. if选择语句与switch选择语句的比较、区别及应用场景
  17. Hdoj 2050.折线分割平面 题解
  18. ubuntu上Android开发环境及依赖项
  19. Redis setnx命令 分布式缓存
  20. springboot系列十五、springboot集成PageHelper

热门文章

  1. 一块移动硬盘怎样兼容Mac和Windows系统,并且可以在time machine上使用
  2. html 常用标签 a form input 标签 等等等
  3. HDU 1002 - A + B Problem II - [高精度]
  4. [No0000B8]WPF或Winform调用系统Console控制台显示信息
  5. Lombok安装及使用
  6. SQL常用语法大全
  7. 【socket-python应用】控制泓格ET-7044通信模块输入DI输出DO
  8. GBDT原理学习
  9. VSCode代码修改后跑起来没反应,打开本地文件,代码没变化
  10. IIS下实现帝国CMS搜索页伪静态