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
template <el-table :data="dataList"&...
JDK Installation I won't go into too much det...
Recommended articles: Click on the lower right co...
1. Create a database 2. Create a table 1. Create ...
Let's take a look at the code file structure ...
1. Server environment configuration: 1. Check dis...
Table of contents Master-slave replication mechan...
Table of contents Preface Earlier iterations Iter...
Table of contents A brief overview of the replica...
Today we will implement a fragmented image loadin...
Table of contents 1. Concept Memory management mo...
Recently, due to work needs, I need to format num...
I have recently been developing a visual operatio...
In the following example, when the width of the td...
By default, the border of the table is 0, and we ...