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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM