求时间和函数

2023年4月15日,北京,我需要的是一个能计算两个时间点之间差异的函数。
2023年4月,北京,求时间和函数,得:

当前时间:

使用函数:

function getCurrentTime() { var now = new Date(); var year = now.getFullYear(); var month = now.getMonth() + 1; // 月份是从0开始的 var day = now.getDate(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds(); return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds; }

调用示例:

document.getElementById('time').innerText = getCurrentTime();

相关推荐

公考

2026-02-20 05:06:06 推荐