Files
djby-crawler/src/utils/index.js
2025-07-04 10:41:58 +08:00

15 lines
495 B
JavaScript

function isValidDateTime(datetimeStr) {
// 尝试将字符串转换为 Date 对象
const date = new Date(datetimeStr);
// 检查转换后的日期是否是有效日期
return !isNaN(date.getTime()) &&
date.toString() !== 'Invalid Date';
}
async function randomDelay(min = 5000, max = 20000) {
const delay = Math.floor(Math.random() * (max - min + 1)) + min;
await new Promise(resolve => setTimeout(resolve, delay));
}
module.exports = { isValidDateTime, randomDelay };