将Python 'min:sec' string 转换成一个看起来一样的时间对象,需要用jQuery tablesorter 正确排序
Convert Python 'min:sec' string into a time object that looks the same, needs to be sorted properly by jQuery tablesorter
出于某种原因,tablesorter 仅适用于表示时间低于“25:00”的字符串。例如,它将高于“25:00”的任何内容置于低于“24:12”或“09:24”的位置。所以我可能需要将字符串转换为时间格式。能够在表格排序器中使用 col-index: { sorter: 'time'}
。
这是现在的样子
我已经阅读了日期时间和时间文档,在 SO 上找到了一些很好的答案,但找不到我需要的东西。
我得到的最接近的是:
from datetime import datetime
datetime_object = datetime.strptime('12:55', '%M:%S')
print(datetime_object)
>>> 1900-01-01 00:12:55
time() 方法用于仅从给定的日期时间对象中获取时间。
from datetime import datetime
datetime_object = datetime.strptime('12:55', '%M:%S').time()
print(str(datetime_object)[3:])
输出:
12:55
如果您使用的是我的fork of tablesorter, there is an additional countdown parser。加载 parser-duration.js
文件并将排序器设置为 "countdown".
出于某种原因,tablesorter 仅适用于表示时间低于“25:00”的字符串。例如,它将高于“25:00”的任何内容置于低于“24:12”或“09:24”的位置。所以我可能需要将字符串转换为时间格式。能够在表格排序器中使用 col-index: { sorter: 'time'}
。
这是现在的样子
我已经阅读了日期时间和时间文档,在 SO 上找到了一些很好的答案,但找不到我需要的东西。
我得到的最接近的是:
from datetime import datetime
datetime_object = datetime.strptime('12:55', '%M:%S')
print(datetime_object)
>>> 1900-01-01 00:12:55
time() 方法用于仅从给定的日期时间对象中获取时间。
from datetime import datetime
datetime_object = datetime.strptime('12:55', '%M:%S').time()
print(str(datetime_object)[3:])
输出:
12:55
如果您使用的是我的fork of tablesorter, there is an additional countdown parser。加载 parser-duration.js
文件并将排序器设置为 "countdown".