1234567891011121314151617181920212223242526 |
- // 防抖函数
- function debounce(func, wait) {
- let timeout;
- return function (...args) {
- clearTimeout(timeout);
- timeout = setTimeout(() => func.apply(this, args), wait);
- };
- }
- /**
- * 将时间戳转换为字符串格式 YYYY-MM-DD HH:mm:ss
- * @param {number} timestamp - 时间戳(毫秒)
- * @returns {string} 格式化后的日期字符串
- */
- function timestampToString(timestamp) {
- const date = new Date(timestamp * 1000);
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, "0");
- const day = String(date.getDate()).padStart(2, "0");
- const hours = String(date.getHours()).padStart(2, "0");
- const minutes = String(date.getMinutes()).padStart(2, "0");
- const seconds = String(date.getSeconds()).padStart(2, "0");
- return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
- }
- export default { debounce, timestampToString };
|