var debouncedAjax = debounce(infiniteDictionaryScrollAjax, 500); // debounce here
$("div").on('scroll', debouncedAjax); // use debounced
function infiniteDictionaryScrollAjax() {
$("div").off("scroll");
$.ajax({
type: "POST",
url: "/someURL",
data: {
data: "data"
}
})
.done(function(response) {
$("div").append("<br>appendedData");
$("div").on('scroll', debouncedAjax); // use debounced
})
.fail(function() {
$("div").append("<br>appendedError");
$("div").on('scroll', debouncedAjax); // use debounced
});
}
function debounce(func, timeToWait) {
var timeout;
return function() {
clearTimeout(timeout);
timeout = setTimeout(func, timeToWait);
};
}
调试后我在from datetime import datetime, timedelta
api_time = datetime.strptime(parsed_json["result"]["parameters"]["time"], "%H:%M:%S")
获得的内容是api_time
。我想要的只是900-01-01 12:30:22
。我已经检查了其他文档,12:30:22
应该已经完成了,但它没有用。
答案 0 :(得分:0)
一个快速的解决方案,如果您的输入没有改变。
from datetime import datetime, timedelta
api_time = datetime.strptime("1900-01-01 12:30:22".split(" ")[1], "%H:%M:%S")
print api_time
>1900-01-01 12:30:22
在你的情况下:
api_time = datetime.strptime(parsed_json["result"]["parameters"]["time"], "%H:%M:%S")
或者您可以构建datetime
对象,然后访问second
,minute
,hour
属性,如下所示:
from datetime import datetime, timedelta
api_time = datetime.strptime("1900-01-01 12:30:22", "%Y-%m-%d %H:%M:%S")
print "{0}:{1}:{2}".format(api_time.second, api_time.minute, api_time.hour)
>22:30:12
答案 1 :(得分:-1)
您可以将它们从datetime转换为string,然后只使用string split:
a = '1900-01-01 12:30:22'
a.split(' ')[1]
-->
from datetime import datetime
api_time = datetime(1900, 01, 01, 12, 30, 22).strftime("%Y-%m-%d %H:%M:%S")
api_time.split(' ')[1]