function getTimeAfterSeconds(currentTime, seconds) { const date = new Date(currentTime); date.setSeconds(date.getSeconds() + seconds); return date; }

// 使用示例 const currentTime = new Date(); const timeAfterTenSeconds = getTimeAfterSeconds(currentTime, 10); console.log(timeAfterTenSeconds); // 打印当前时间加 10 秒后的时间

JavaScript 函数封装:获取当前时间并添加秒数

原文地址: https://www.cveoy.top/t/topic/n9Qm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录