This article shares the specific code for JavaScript to achieve a simple calendar effect for your reference. The specific content is as follows The effect is as follows: Code: <!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> <style> * { margin: 0; padding: 0; box-sizing: border-box; } #box { width: 400px; height: 502px; border: 2px solid orange; margin: 50px auto; font-size: 48px; text-align: center; } #ym { height: 100px; line-height: 100px; } #d { height: 200px; line-height: 200px; background-color: orange; font-size: 72px; } #w { height: 100px; line-height: 100px; } #hms { height: 100px; line-height: 100px; } </style> </head> <body> <div id="box"> <div id="ym"></div> <div id="d"></div> <div id="w"></div> <div id="hms"></div> </div> <script> //Call the getDateAndTime method getDateAndTime(); //Start the timer and call the getDateAndTime method window.setInterval(getDateAndTime, 1000); function getDateAndTime() { //Get the current date and time of the system var date = new Date(); //Extract the elements of date and time var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var week = date.getDay(); var hour = date.getHours(); var minute = date.getMinutes(); var second = date.getSeconds(); //Process the week format switch (week) { case 0: week = 'Sunday'; break; case 1: week = 'Monday'; break; case 2: week = 'Tuesday'; break; case 3: week = 'Wednesday'; break; case 4: week = 'Thursday'; break; case 5: week = 'Friday'; break; case 6: week = 'Saturday'; break; } //Define function to process the format of hours, minutes and seconds function formatHMS(time) { if (time < 10) { return '0' + time; } else { return time; } } //Get the page element var ym = document.getElementById('ym'); var d = document.getElementById('d'); var w = document.getElementById('w'); var hms = document.getElementById('hms'); //Write the date and time to the page ym.innerHTML = year + 'year' + month + 'month'; d.innerHTML = day; w.innerHTML = week; hms.innerHTML = hour + 'hour' + minute + 'minute' + second + 'second'; } </script> </body> </html> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Solution to MySql Error 1698 (28000)
>>: MySQL password modification example detailed explanation
Chatbots can save a lot of manual work and can be...
Table of contents 1. Steps to use Jquery: (1) Imp...
Table of contents aforementioned VARCHAR Type VAR...
This article example shares the specific code of ...
Table of contents 1. Location Object 1. URL 2. Pr...
Problem Description After installing Qt5.15.0, an...
Table of contents Implementing state sharing base...
There are three main ways of MySQL replication: S...
Often, after a web design is completed, the desig...
1. The error information reported when running th...
Delete a file by its inode number First use ls -i...
Because I want to write a web page myself, I am al...
Recently, Microsoft released the 2019 server syst...
Omit the protocol of the resource file It is reco...
Table of contents 1. Initialization structure 2. ...