info_rent = MysqlUtils.select_yezhu_rent()
info_sale = MysqlUtils.select_yezhu_sale()
now_time = datetime.datetime.now()
#now time type is datetime and mysql spidertime is also datetime
for i in info_rent:
city = i[0]
spidertime = i[1]
d_time = now_time.timestamp()-spidertime.timestamp()
#此处计算直接得出秒数,因为是时间戳的相减
d_time1 = now_time-spidertime
print(d_time1.seconds) #业务,采集报警,计算当前时间与数据库中采集时间的间隔
数据库存的时间类型是datetime timedelta (时间间隔中的方法,只支持days 和 seconds)
如果要计算分钟和小时,需要乘以60 60、

重点,timedelta 时间间隔算法,只支持days 和 seconds

不支持hour 和min 方法

python3 datetime 时间格式相减 计算间隔的更多相关文章

  1. Excel 时间格式相减

    https://jingyan.baidu.com/article/3065b3b6e8b9dabecff8a4d6.html datedif函数是excel的隐藏函数,主要用于计算日期之差,不是四舍 ...

  2. C# DateTime时间格式转换为Unix时间戳格式

    double ntime=dateTimeToUnixTimestamp(DateTime.Now); long g1 = GetUnixTimestamp(); long g2 = ConvertD ...

  3. c# DateTime时间格式和JAVA时间戳格式相互转换

    /// java时间戳格式时间戳转为C#格式时间 public static DateTime GetTime(long timeStamp) { DateTime dtStart = TimeZon ...

  4. DateTime时间格式转换为Unix时间戳格式

    /// <summary> /// 将DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name="date ...

  5. MySQL 时间函数加减计算

    一.MySQL 获得当前日期时间 函数 1.1 获得当前日期 + 时间(date + time) 函数:now() mysql> select now();+———————+| now() |+ ...

  6. python中将HTTP头部中的GMT时间转换成datetime时间格式

    原文: https://blog.csdn.net/zoulonglong/article/details/80585716 需求背景:目前在做接口的自动化测试平台,由于接口用例执行后返回的结果中的时 ...

  7. oracle 时间格式转化以及计算

    --A表中的日期字段 create_date   例如:2017-08-05  转化为2017年8月5日   oracle 在这里的双引号会忽略 select to_char(to_date(tt.c ...

  8. C# 两个时间相减 计算两个时间差(年月日时分秒)

    DateTime dt1; DateTime dt2; int days=(dt2.Date-dt1.Date).Days;   或者 TimeSpan ts = dt2 -dt1;          ...

  9. python的内置模块time和datetime的方法详解以及使用(python内的time和datetime时间格式)

    time内置模块的方法 1.time() 时间戳 time() -> floating point number  浮点数 Return the current time in seconds ...

随机推荐

  1. mysql索引分类

    mysql索引分类 一.总结 一句话总结: 主键索引:设定为主键后数据库会自动建立索引,innodb为聚簇索引 单值索引:一个索引只包含单个列,一个表可以有多个单列索引:CREATE INDEX id ...

  2. mysql数据库学习二

    最近又复习了mysql中的一些概念:视图,触发器,存储过程,函数,事务,记录下. 1.视图 视图是一个虚拟表,本身并不存储数据,当sql在操作视图时所有数据都是从其他表中查出来的,因此其本质是:根据S ...

  3. CIEDE2000色差公式相关

    色差公式发展的三个重要的阶段:1976年以前(CIELAB和CIELUV的采用).1976年到2001年(CIEDE2000色差公式的推荐).2001年以后. 国际照明委员会1998年成立了技术委员会 ...

  4. SpringBoot之HandlerInterceptor拦截器的使用 ——(一)

    HandlerInterceptor简介拦截器我想大家都并不陌生,最常用的登录拦截.或是权限校验.或是防重复提交.或是根据业务像12306去校验购票时间,总之可以去做很多的事情.我仔细想了想这里我分三 ...

  5. swift 第四课 随意 设置button 图片和文字 位置

    项目中经常遇到按钮改变文字和图片位置的情况,所以尝试写一个 button 的分类: 参照连接 http://blog.csdn.net/dfqin/article/details/37813591 i ...

  6. 微信小程序的target和currentTarget的区别

    https://www.jb51.net/article/160886.htm 在小程序的事件回调触发时,会接收一个事件对象,事件对象的参数中包含一个target和currentTarget属性,接下 ...

  7. logging配置

    import logging def handle(): # 1.定义logger对象:负责产生日志,然后交给Filter过滤,然后交给不同的Handler输出 logger = logging.ge ...

  8. JPG文件结构分析

    [转自网络  作者:一 江秋水] 一.简述 JPEG是一个压缩标准,又可分为标准 JPEG.渐进式JPEG及JPEG2000三种: ①标准JPEG:以24位颜色存储单个光栅图像,是与平台无关的格式,支 ...

  9. A+B Problem Plus and A-B Problem Plus and A*B Problem Plus

    //we have defined the necessary header files here for this problem. //If additional header files are ...

  10. jqGrid清空表格

    $("#jqGrid").jqGrid("setGridParam",{ datatype:'local', data : [], page:1 }).trig ...