以下是一段使用JavaScript编写的简单易懂的闹钟示例代码: javascript Copy code //获取当前时间function getCurrentTime() { var date = new Date(); var hours = date.getHours(); var minutes = date.getMinutes(); var seconds = date.getSeconds(); //将小时、分钟、秒数格式化为两位数hours = formatTime(hours); minutes = formatTime(minutes); seconds = formatTime(seconds); //返回格式化后的当前时间return hours + ":" + minutes + ":" + seconds; } //格式化时间为两位数function formatTime(time) { if (time < 10) { time = "0" + time; } re