发布时间:2019-09-16 07:35:21编辑:auto阅读(1728)
例如:时间格式是
2020-01-29 16:31:31和2025-01-23 15:30:30,怎么求得两个时间相减的时间差? 具体如下: import time as t import datetime as d #定义时间差函数 def myDate(date1, date2): date1 = t.strptime(date1, "%Y-%m-%d %H:%M:%S") date2 = t.strptime(date2, "%Y-%m-%d %H:%M:%S") startTime = t.strftime("%Y-%m-%d %H:%M:%S", date1) endTime = t.strftime("%Y-%m-%d %H:%M:%S", date2) startTime = d.datetime.strptime(startTime,"%Y-%m-%d %H:%M:%S") endTime = d.datetime.strptime(endTime,"%Y-%m-%d %H:%M:%S") date = endTime- startTime return date #参数赋值 date1 = "2020-01-29 16:31:31" date2 = "2025-01-23 15:30:30" #获得时间差秒数 seconds = myDate(date1, date2).seconds #获得时间差 date = myDate(date1, date2) print(seconds) print(date)
上一篇: python升级2.6到2.7
下一篇: mac安装python-ldap
47842
46390
37283
34733
29313
25973
24916
19951
19544
18030
5792°
6413°
5927°
5961°
7064°
5911°
5944°
6438°
6404°
7778°