使用js获取当前的时间日期
function CurrentTime() { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hour = date.getHours(); var minute = date.getMinutes(); var second = date.getSeconds(); month = month < 10 ? ("0" + month) : month; day = day < 10 ? ("0" + day) : day; hour = hour < 10 ? ("0" + hour) : hour; minute = minute < 10 ? ("0" + minute) : minute; second = second < 10 ? ("0" + second) : second; var Timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second; //在页面上插入日期 $("#current-time").html(Timer); setTimeout(function () { CurrentTime(); }, 1000); }
在页面内容加载完成后执行