需要知道如何在几小时而不是一天内自动删除 Javascript 解析云代码
Need to know how to autodelete in hours instead of one day Javascript Parse Cloud Code
我有这个云代码,每 24 小时从我的解析 table 中删除对象。我想让这段代码每 5 小时而不是 24 小时删除一次对象。谁能帮我修改这段代码或指导我做我需要做的事?
Parse.Cloud.job('deleteOldPosts', function(request, status) {
// All access
Parse.Cloud.useMasterKey();
var today = new Date();
var days = 1;
var time = (days * 24 * 3600 * 1000); // OTHER LOGIC FOR HOURS???
var expirationDate = new Date(today.getTime() - (time));
var query = new Parse.Query('Places');
// All posts have more than 1 day //
query.lessThan('createdAt', expirationDate);
query.find().then(function (posts) {
Parse.Object.destroyAll(posts, {
success: function() {
status.success('All posts are removed.');
},
error: function(error) {
status.error('Error, posts are not removed.');
}
});
}, function (error) {});
});
提前致谢!
为了实现它,您需要从当前日期减去 5 小时,因此您需要使用以下代码:
var now = new Date();
var expirationDate = new Date();
expirationDate.setHours(now.getHours() - 5);
我有这个云代码,每 24 小时从我的解析 table 中删除对象。我想让这段代码每 5 小时而不是 24 小时删除一次对象。谁能帮我修改这段代码或指导我做我需要做的事?
Parse.Cloud.job('deleteOldPosts', function(request, status) {
// All access
Parse.Cloud.useMasterKey();
var today = new Date();
var days = 1;
var time = (days * 24 * 3600 * 1000); // OTHER LOGIC FOR HOURS???
var expirationDate = new Date(today.getTime() - (time));
var query = new Parse.Query('Places');
// All posts have more than 1 day //
query.lessThan('createdAt', expirationDate);
query.find().then(function (posts) {
Parse.Object.destroyAll(posts, {
success: function() {
status.success('All posts are removed.');
},
error: function(error) {
status.error('Error, posts are not removed.');
}
});
}, function (error) {});
}); 提前致谢!
为了实现它,您需要从当前日期减去 5 小时,因此您需要使用以下代码:
var now = new Date();
var expirationDate = new Date();
expirationDate.setHours(now.getHours() - 5);