• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python获取指定时间差的时间实例详解

python获取指定时间差的时间实例详解

作者:lqh 字体:[增加 减小] 来源:互联网

lqh 通过本文主要向大家介绍了python开发技术详解,python os模块详解,python正则表达式详解,python 字典详解,python类详解等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

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
</div>

运行后所得结果:

2016-04-30 20:25:56 
2016-05-06 20:25:56
</div>

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

</div>

您可能想查找下面的文章:

  • python中OrderedDict的使用方法详解
  • Python中异常重试的解决方案详解
  • 详解python 字符串和日期之间转换 StringAndDate
  • Python 操作MySQL详解及实例
  • python中OrderedDict的使用方法详解
  • Python中异常重试的解决方案详解
  • 详解python 字符串和日期之间转换 StringAndDate
  • Python 操作MySQL详解及实例
  • Python 登录网站详解及实例
  • 详解Python中类的定义与使用

相关文章

  • Python基本语法经典教程
  • 将Django框架和遗留的Web应用集成的方法
  • python生成IP段的方法
  • python实现的希尔排序算法实例
  • Python切片用法实例教程
  • Python中super的用法实例
  • python实现ping的方法
  • Django发送html邮件的方法
  • 编写同时兼容Python2.x与Python3.x版本的代码的几个示例
  • Python实现对比不同字体中的同一字符的显示效果

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python pickle类库介绍(对象序列化和反序列化)
    • Python的“二维”字典 (two-dimension dictionary)定义与实现方法
    • 使用Django的模版来配合字符串翻译工作
    • videocapture库制作python视频高速传输程序
    • 利用PyInstaller将python程序.py转为.exe的方法详解
    • TensorFlow——Checkpoint为模型添加检查点的实例
    • Python中对象迭代与反迭代的技巧总结
    • Python中asyncore异步模块的用法及实现httpclient的实例
    • python装饰器decorator介绍
    • pygame学习笔记(1):矩形、圆型画图实例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有