我是靠谱客的博主 甜甜航空,这篇文章主要介绍python 当前时间多加一天、一小时、一分钟,现在分享给大家,希望可以做个参考。

首先看下,datetime的使用

import datetime
>>> print datetime.datetime.now()
2017-07-15 15:01:24.619000
  • 1
  • 2
  • 3
  • 4

格式化时间

>>> print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
2017-07-15 15:01:35
>>> print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
2017-07-15 15:01
>>> print datetime.datetime.now().strftime("%Y%m%d")
20170715
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

多加一天

>>> print (datetime.datetime.now()+datetime.timedelta(days=1)).strftime("%Y-%m-%
d %H:%M:%S")
2017-07-16 15:12:42
>>>
  • 1
  • 2
  • 3
  • 4

多加一小时

>>> print (datetime.datetime.now()+datetime.timedelta(hours=1)).strftime("%Y-%m-
%d %H:%M:%S")
2017-07-15 16:10:43
>>>
  • 1
  • 2
  • 3
  • 4

多加一分钟

>>> print (datetime.datetime.now()+datetime.timedelta(minutes=1)).strftime("%Y-%
m-%d %H:%M:%S")
2017-07-15 15:12:56
>>>

最后

以上就是甜甜航空最近收集整理的关于python 当前时间多加一天、一小时、一分钟的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(93)

评论列表共有 0 条评论

立即
投稿
返回
顶部