一般Oracle得到的时间格式为:
1970-01-05 01:23:56.297
为了计算两个时间的差值:
1970-01-05 01:23:56.297
与 1970-01-05 01:24:57.432
Python代码如下:
#!/usr/bin/python3.4
# -*- coding: utf-8 -*-
import time
def Caltime(date1, date2):
# 格式化时间
date1 = time.strptime(date1, "%Y-%m-%d %H:%M:%S.%f")
date2 = time.strptime(date2, "%Y-%m-%d %H:%M:%S.%f")
# 转化为时间戳
date1 = time.mktime(date1)
date2 = time.mktime(date2)
date = date2 - date1
return date
if __name__ == '__main__':
date1 = "1970-01-05 01:23:56.297"
date2 = "1970-01-05 01:24:57.432"
result = Caltime(date1, date2)
print(result)
# 61.0
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有