python学习datetime模块

简介:

 下面记录下datetime模块一些使用的方法,先打印出当前时间,然后再打印出前后3天,后3小时,后3分钟,后3秒钟的表达方式,下面看下代码:

 

 
  1. import datetime 
  2. now = datetime.datetime.now() 
  3. print now 
  4. #往后3小时,2天,3分钟,3秒钟 
  5. print datetime.datetime.now() + datetime.timedelta(hours=3
  6. print datetime.datetime.now() + datetime.timedelta(days=3
  7. print datetime.datetime.now() + datetime.timedelta(minutes=3
  8. print datetime.datetime.now() + datetime.timedelta(seconds=3

下面看看效果:

 

 


 
  1. 2011-03-04 14:07:18.437000 
  2. 2011-03-07 14:07:18.437000 
  3. 2011-03-04 17:07:18.437000 
  4. 2011-03-04 14:10:18.437000 
  5. 2011-03-04 14:07:21.437000 

 本文转自你是路人甲还是霍元甲博客51CTO博客,原文链接http://blog.51cto.com/world77/506415如需转载请自行联系原作者


world77

相关文章
|
4天前
|
Python
python学习3-选择结构、bool值、pass语句
python学习3-选择结构、bool值、pass语句
|
1天前
|
测试技术 Python
Python 有趣的模块之pynupt——通过pynput控制鼠标和键盘
Python 有趣的模块之pynupt——通过pynput控制鼠标和键盘
|
1天前
|
Serverless 开发者 Python
《Python 简易速速上手小册》第3章:Python 的函数和模块(2024 最新版)
《Python 简易速速上手小册》第3章:Python 的函数和模块(2024 最新版)
25 1
|
2天前
|
机器学习/深度学习 算法 Python
使用Python实现集成学习算法:Bagging与Boosting
使用Python实现集成学习算法:Bagging与Boosting
15 0
|
3天前
|
Python
python学习-函数模块,数据结构,字符串和列表(下)
python学习-函数模块,数据结构,字符串和列表
25 0
|
4天前
|
Python
python学习14-模块与包
python学习14-模块与包
|
4天前
|
Python
python学习12-类对象和实例对象
python学习12-类对象和实例对象
|
4天前
|
数据采集 Python
python学习9-字符串
python学习9-字符串
|
4天前
|
Python
python学习10-函数
python学习10-函数
|
4天前
|
存储 索引 Python
python学习7-元组
python学习7-元组