一般Oracle得到的时间格式为:

1970-01-05 01:23:56.297

为了计算两个时间的差值:

1970-01-05 01:23:56.2971970-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
04-30 06:56