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

猜你喜欢

转载自www.cnblogs.com/BH8ANK/p/9449056.html