本文章提供了一个简单的JavaScript方法来获取并显示当前系统的完整日期与时间信息(包括年、月、日、时、分、秒),便于网页开发中使用。
在JavaScript中可以使用以下简易代码来获取当前系统时间(年月日小时分钟秒):
```javascript
function getCurrentDateTime() {
var now = new Date();
function padZero(num) { //辅助函数,用于补零处理
return num < 10 ? 0 + num : + num;
}
var year = now.getFullYear(),
month = padZero(now.getMonth() + 1),
day = padZero(now.getDate()),
hours = padZero(now.getHours()),
minutes = padZero(now.getMinutes()),
seconds = padZero(now.getSeconds());
return year + - + month + - + day + + hours + : + minutes+ : + seconds;
}
console.log(getCurrentDateTime());
```