【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'))

 

posted @ 2018-08-09 15:10  BH8ANK  阅读(1511)  评论(0编辑  收藏  举报