我减去两个日期并计算小时差
c_date = "2011-03-23 12:52:14"
c_obj_date = datetime.datetime.strptime(c_date, "%Y-%m-%d %H:%M:%S")
n_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print "Creation Date:", c_date
print "Current Date: ", n_date
hours = abs(n_date - c_obj_date).total_seconds() / 3600.0
print hours
但是这给了我这个错误:
File "./eight.py", line 69, in zabbix_result
hours = abs(n_date - c_obj_date).total_seconds() / 3600.0
TypeError: unsupported operand type(s) for -: 'str' and 'datetime.datetime'
我正在使用python2.4
更新:
我现在用
n_date = datetime.datetime.now()
但total_seconds() 在python2.4 中不起作用??知道如何减去两个日期时间对象并获得小时差吗?