JavaScript code to achieve a simple calendar effect

JavaScript code to achieve a simple calendar effect

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:
  • js css+html to realize a simple calendar
  • A guide to using calendar.js, a lightweight native js calendar plugin
  • JS learning a simple calendar control
  • Vue.js creates Calendar effect
  • JS Calendar Recommendation
  • Pure js simple calendar implementation code
  • js writes a simple calendar effect for the day [implementation code]
  • js calendar control (accurate to the minute)
  • PHP+javascript calendar control
  • Simple JS calendar control example code

<<:  Solution to MySql Error 1698 (28000)

>>:  MySQL password modification example detailed explanation

Recommend

Vue event's $event parameter = event value case

template <el-table :data="dataList"&...

Steps to split and compress CSS with webpack and import it with link

Let's take a look at the code file structure ...

Sample code for partitioning and formatting a disk larger than 20TB on centos6

1. Server environment configuration: 1. Check dis...

Comprehensive analysis of MySql master-slave replication mechanism

Table of contents Master-slave replication mechan...

In-depth explanation of iterators in ECMAScript

Table of contents Preface Earlier iterations Iter...

MySQL master-slave replication delay causes and solutions

Table of contents A brief overview of the replica...

Implementing image fragmentation loading function based on HTML code

Today we will implement a fragmented image loadin...

A detailed introduction to Linux memory management and addressing

Table of contents 1. Concept Memory management mo...

Detailed explanation of formatting numbers in MySQL

Recently, due to work needs, I need to format num...

Sample code for implementing history in vuex

I have recently been developing a visual operatio...

td width problem when td cells are merged

In the following example, when the width of the td...

HTML table markup tutorial (2): table border attributes BORDER

By default, the border of the table is 0, and we ...