💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 1.Math ~~~ Math.ceil() Math.floor() Math.round() Math.random() Math.max() Math.min() ~~~ ## 2.Date ~~~ //获取当前时间 var oDate = new Date(); var year = oDate.getFullYear(); var month = oDate.getMonth(); var date = oDate.getDate(); var hour = oDate.getHours(); var minute = oDate.getMinutes(); var second = oDate.getSeconds(); var mill = oDate.getTime(); ~~~ ~~~ //月份从0开始 var month = oDate.getMonth()+1; //星期从0开始,0表示星期天 //0,1,2,3,4,5,6 var day = oDate.getDay(); ~~~ leg:实现一个数码时钟 * 思路 * [ ] 获取系统时间 * [ ] Date对象 * [ ] getHours,getMinutes,getSeconds * [ ] 显示系统时间 * [ ] 字符串连接 * [ ] 小于10补零 * [ ] 使用定时器 setInterval() ~~~ //HTML <div id="clock"> <img src="images/0.png" alt=""> <img src="images/0.png" alt=""> <img src="images/0.png" alt=""> <img src="images/0.png" alt=""> <img src="images/0.png" alt=""> <img src="images/0.png" alt=""> </div> showTime(); setInterval(showTime,1000) function showTime() { var d = new Date(); var hour = d.getHours(); var minute = d.getMinutes(); var second = d.getSeconds(); //1.小10补零 function add(time) { if (time < 10) { return "0" + time } else { return time + ""; } } var allTime = add(hour) + add(minute) + add(second); //2.分割字符串显示系统时间 var arr = allTime.split(""); console.log(arr); var imgs = document.getElementsByTagName("img"); for (let i = 0; i < imgs.length; i++) { imgs[i].src = "images/" + arr[i] + ".png" } } ~~~