您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

教你如何使用python获取指定时间差的时间

2025/1/15 19:51:34发布14次查看
这篇文章主要介绍了python获取指定时间差的时间实例详解的相关资料,需要的朋友可以参考下
python获取指定时间差的时间实例详解
在分析数据的时间经常需要截取一定范围时间的数据,比如三天之内,两小时前等等时间要求的数据,因此将该部分经常需要用到的功能模块化,方便以后以后用到的时候复用。在此,也分享给大家。
import time import sys reload(sys) def get_day_of_day(utc=false, days=0, hours=0, miutes=0, seconds=0): ''''''' if days>=0,date is larger than today if days<0,date is less than today date format = "yyyy-mm-dd" ''' now = time.time() timenew = now + days*24*60*60 + hours*60*60 + miutes*60 + seconds if utc : timenew = timenew + time.timezone t = time.localtime(timenew) return time.strftime('%y-%m-%d %h:%m:%s', t) #使用utc时间 两小时前 t = get_day_of_day(true,0,-2) print t #当地时间 三天前 t = get_day_of_day(false,-3) print t #当地时间 三天后 t = get_day_of_day(false,3) print t
运行后所得结果:
2016-04-30 20:25:56 2016-05-06 20:25:56
以上就是教你如何使用python获取指定时间差的时间的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product