python获取当前,昨天,明天时间
2024-10-15 15:10:18
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天前的时间
最新文章
- angular $http请求
- AOP programming paradiag
- LVM逻辑卷的创建及使用
- 李洪强漫谈iOS开发[C语言-046]-统计输入字符个数
- python高效解析日志入库
- 洛谷P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- iOS开发——实战OC篇&;环境搭建之纯代码(玩转UINavigationController与UITabBarController)
- 1218. Episode N-th: The Jedi Tournament(bfs)
- eCos中断模型
- AjaxPro使用说明
- Hadoop流程---从tpch到hive
- Linux下编译安装Apache及模块
- javascript方法的方法名慎用close
- call是什么?一次说个明白
- Docker----起步
- if选择语句与switch选择语句的比较、区别及应用场景
- Hdoj 2050.折线分割平面 题解
- ubuntu上Android开发环境及依赖项
- Redis setnx命令 分布式缓存
- springboot系列十五、springboot集成PageHelper
热门文章
- 一块移动硬盘怎样兼容Mac和Windows系统,并且可以在time machine上使用
- html 常用标签 a form input 标签 等等等
- HDU 1002 - A + B Problem II - [高精度]
- [No0000B8]WPF或Winform调用系统Console控制台显示信息
- Lombok安装及使用
- SQL常用语法大全
- 【socket-python应用】控制泓格ET-7044通信模块输入DI输出DO
- GBDT原理学习
- VSCode代码修改后跑起来没反应,打开本地文件,代码没变化
- IIS下实现帝国CMS搜索页伪静态