【python 3.6】python获取当前时间及过去或将来的指定时间
生活随笔
收集整理的這篇文章主要介紹了
【python 3.6】python获取当前时间及过去或将来的指定时间
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近有個查詢api,入參需要一個startTime,一個endTime,剛好用到datetime。
留此記錄。
#python 3.6
#!/usr/bin/env python
# -*- coding:utf-8 -*-
__author__ = 'BH8ANK'
import datetime
now_time = datetime.datetime.now()
print(now_time.strftime('%Y-%m-%d %H:%M:%S'))
#獲取4小時以前的時間點
last_time = now_time + datetime.timedelta(hours = -4)
print(last_time.strftime('%Y-%m-%d %H:%M:%S'))
總結
以上是生活随笔為你收集整理的【python 3.6】python获取当前时间及过去或将来的指定时间的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 红盟冰儿
- 下一篇: paloalto防火墙安装内容和软件更新