1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| <!DOCTYPE html> <html> <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> <style> * { margin: 0; padding: 0; } ul { width: 300px; height: 70px; border: 1px solid black; text-align: center; margin: 50px auto; } ul li { list-style: none; margin-top: 10px; width: 50px; height: 50px; background-color: brown; color: #fff; line-height: 50px; font-size: 20px; display: inline-block; } h2 { text-align: center; margin-top: 50px; } </style> </head> <body> <h2>距离20250618还有这么多天</h2> <ul class="box"> <li id="dayBox">xx</li>天 <li id="hourBox">xx</li>时 <li id="minutesBox">xx</li>分 <li id="secondBox">xx</li>秒 </ul> <script> function tsfm(end) { var now = new Date() var end = new Date(end) var arr = {} var timeDiff = Math.abs(now - end) var day = parseInt(timeDiff / 86400000) var hour = parseInt((timeDiff - (day * 86400000)) / 3600000) var minutes = parseInt((timeDiff - (day * 86400000) - (hour * 3600000)) / 60000) var second = parseInt((timeDiff - (day * 86400000) - (hour * 3600000) - (minutes * 60000)) / 1000) arr['day'] = day arr['hour'] = hour arr['minutes'] = minutes arr['second'] = second console.log(arr) return arr } function changetime(end) { var arr1 = tsfm(end) dayBox.innerHTML = arr1.day hourBox.innerHTML = arr1.hour minutesBox.innerHTML = arr1.minutes secondBox.innerHTML = arr1.second console.log('我执行了') } var end = '2025/06/04 00:00:00' changetime(end) var timeid1 = setInterval(changetime, 1000, end) </script> </body> </html>
|