一、动态时间动态走动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <body> <div id="box"></div> <script type="text/javascript"> function showtime() { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; month = month < 10 ? '0' + month : month; var day = date.getDate(); day = day < 10 ? '0' + day : day; var week = '日一二三四五六'.charAt(date.getDay()); // 使用charAt函数提取相应汉字 var hour = date.getHours(); hour = hour < 10 ? '0' + hour : hour; // 用三目运算符调整数字显示格式 var minute = date.getMinutes(); minute = minute < 10 ? '0' + minute : minute; var second = date.getSeconds(); second = second < 10 ? '0' + second : second; var current = year + '-' + month + '-' + day + ' ' + '星期' + week + ' ' + hour + ':' + minute + ':' + second; var o = document.getElementById('box'); o.innerHTML = current; setTimeout(showtime, 1000); } showtime(); </script> </body> </html>
标签:month,JS,date,second,时间,var,动态,day,minute From: https://www.cnblogs.com/Ryan-DHQ/p/17373891.html